Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to pthread_create in c program on eclipse (Fedora)

Tags:

c

eclipse

fedora

I have a problem in building a c thread program. Program is giving error like "undefined reference to pthread_creat". I searched and found to use gcc options like "gcc -lpthread -o ...."

But I not able to set it for eclipse. I tried to make change in makefile but every time it got replaced with default options. Please help me to set these gcc options and write about where and how to set gcc options in eclipse on fedora 10.

Thanks,

Lokesh

like image 214
Lokesh Avatar asked Dec 02 '10 10:12

Lokesh


People also ask

Why am I getting undefined reference to pthread_create?

Another common cause of the “undefined reference to pthread_create” error is compiling your program with the incorrect compiler flags. You will get the “undefined reference to pthreads” error. While making sure that the pthreads.

What is pthread_create in C?

DESCRIPTION. The pthread_create() function is used to create a new thread, with attributes specified by attr, within a process. If attr is NULL, the default attributes are used. If the attributes specified by attr are modified later, the thread's attributes are not affected.

What is pthread in Linux?

POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time.


1 Answers

to add pthread library to your project flow these steps (in eclipse):

right cklick on the project in the project explorer -> properties -> c/c++ build -> Settings -> linker -> libraries -> add -> pthread -> ok -> rebuild

like image 149
M.ElSaka Avatar answered Oct 20 '22 22:10

M.ElSaka