Pthread_create Linking Error
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company undefined reference to pthread_create' c++ Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs undefined reference to `pthread_create' cmake Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers,
Undefined Reference To Pthread_create Code Blocks
just like you, helping each other. Join them; it only takes a minute: Sign up undefined reference to pthread_create in Linux up vote 162 down vote favorite 60 I picked up the following demo off the web
Undefined Reference To Pthread_create' Makefile
from https://computing.llnl.gov/tutorials/pthreads/ #include #include #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thread #%ld!\n", tid); pthread_exit(NULL); } int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; for(t=0; there for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Undefined Reference To `pthread_create' C++11
of this site About Us Learn more about Stack Overflow the company cmake pthread Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges clion pthread Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: http://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux Sign up compile/link error using pthread up vote 3 down vote favorite I try to make a little program that sorts an array using threads but I can't get it to compile with the thread support. Error: sortieren.c:(.text+0xd7): undefined reference to `ptread_create' I used a make file for easy compiling but also on command line I can't get it to work. Basic http://stackoverflow.com/questions/6332410/compile-link-error-using-pthread code: #include int main(int argc, char **argv) { pthread_t threads[2]; // code snipped int ret = ptread_create(&threads[0], NULL, threadOne(), NULL); printf("ret: %d\n", ret); // code snipped } Make file: sortieren : sortieren.o gcc sortieren.o sortieren.o : sortieren.c gcc -pthread -c sortieren.c Using make sortieren results in this output gcc -pthread -c sortieren.c gcc sortieren.o sortieren.o: In function `main': sortieren.c:(.text+0xd7): undefined reference to `ptread_create' collect2: ld returned 1 exit status make: *** [sortieren] Fehler 1 Of course I tried to google but every "solution" I found didn't worked for me. I tried -pthread or -lpthread everywhere in my make file. To be sure that I didn't do anything wrong in my code, I also tried a public sample: #include #include #include #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thread #%ld!\n", tid); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long t; for(t=0;there for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more http://unix.stackexchange.com/questions/33396/gcc-cant-link-to-pthread about Stack Overflow the company Business Learn more about hiring developers or posting ads http://forums.codeblocks.org/index.php?topic=17290.0 with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The undefined reference best answers are voted up and rise to the top gcc can't link to pthread? up vote 12 down vote favorite 1 I have recently installed XUbuntu 11.10 64bit, but I am having problem compiling the most simple pthread example. Here is the code pthread_simple.c: #include #include main() { pthread_t f2_thread, f1_thread; void *f2(), *f1(); int i1,i2; i1 = 1; i2 = 2; pthread_create(&f1_thread,NULL,f1,&i1); pthread_create(&f2_thread,NULL,f2,&i2); pthread_join(f1_thread,NULL); pthread_join(f2_thread,NULL); } void undefined reference to *f1(int *x){ int i; i = *x; sleep(1); printf("f1: %d",i); pthread_exit(0); } void *f2(int *x){ int i; i = *x; sleep(1); printf("f2: %d",i); pthread_exit(0); } And here is the compile command gcc -lpthread pthread_simple.c The results: lptang@tlp-linux:~/test/test-pthread$ gcc -lpthread pthread_simple.c /tmp/ccmV0LdM.o: In function `main': pthread_simple.c:(.text+0x2c): undefined reference to `pthread_create' pthread_simple.c:(.text+0x46): undefined reference to `pthread_create' pthread_simple.c:(.text+0x57): undefined reference to `pthread_join' pthread_simple.c:(.text+0x68): undefined reference to `pthread_join' collect2: ld returned 1 exit status Does anyone know what's causing the problem? c libraries gcc xubuntu share|improve this question edited Mar 5 '12 at 1:52 asked Mar 4 '12 at 13:14 chtlp 63115 Is it stackexchange's fault that you have empty includes in the first two lines? There should be an #include –Frg Mar 4 '12 at 13:24 Yes, I used the pre environment. It should now display correctly. –chtlp Mar 4 '12 at 13:27 2 Tried gcc -pthread...? –sr_ Mar 4 '12 at 13:42 BTW, please compile with -Wall, you're missing headers. (And sr_ is correct.) –Mat Mar 4 '12 at 13:43 Thanks. I changed -lpthread to -pthread and it worked. –chtlp Mar 4 '12 at 13:51 add a comment| 3 Answers 3 active oldest votes up vote 16 down vote accepted In the
last months will be deleted periodically to fight SPAM! Home Help Search Login Register Wiki Code::Blocks » User forums » Using Code::Blocks » Linking the pthread library « previous next » Send this topic Print Pages: [1] Go Down Author Topic: Linking the pthread library (Read 18511 times) NanoGoner Single posting newcomer Posts: 4 Linking the pthread library « on: December 23, 2012, 08:55:08 pm » I am running ubuntu Linux and am developing a program in C++. In the program I am trying to start a thread with the following code:-----------------------------------------------------------------------------#include void *updater (unsigned char matrix[8][8]);int main (int argc, char **argv){pthread_t mat_threadint iret, i, x;iret = pthread_create(&mat_thread, NULL, updater, matrix);....------------------------------------------------------When I build the program files I get 1 error which is:undefined reference to 'pthread_create'I have installed g++ and gdb and at first I presumed this meant the pthread library file (libpthread.so) was not available.I am told on another C++ forum that I need the following linking command to link the library into the build:g++ *.cpp -pthreadThis is a command line operation.Can some one tell me how I accomplish this within CodeBlocks. I'm brand new to it. Logged jens Administrator Lives here! Posts: 7068 Re: Linking the pthread library « Reply #1 on: December 23, 2012, 09:17:09 pm » You can add any commandline option to to your projects build options ("{Compiler|Linker} settings -> Other [linker ]options").The Code::Blocks manual and our wiki might also be helpful to see what is possible. « Last Edit: December 23, 2012, 09:19:51 pm by jens » Logged Fedora package maintainer for Code::BlocksJens' Debian - nightlies (and release)Fedora [23 - 25]- and CentOS/RedH