Home/Support/Support Forum/Has anyone got applications with pthread calls to build for the CC6 (Yocto)
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Has anyone got applications with pthread calls to build for the CC6 (Yocto)

0 votes

My simple hello world program fails to build with:

undefined reference to `pthread_create'
#include <pthread.h> #include <stdio.h> #include <stdlib.h> //#include <string.h> //#include <sys/time.h> #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(void) { pthread_t threads[NUM_THREADS]; int rc; long t; for( t = 0; t < NUM_THREADS; t++ ) { printf( "In main: creating thread %ld\n", t ); rc = pthread_create( &threads[t], NULL, PrintHello, ( void * )t ); if ( rc ) { printf("ERROR; return code from pthread_create() is %d\n", rc); exit( -1 ); } } /* Last thing that main() should do */ pthread_exit( NULL ); return 0; }

I think it is because the library can't be found, but I don't know how to configure eclipse to include it. Any help appreciated!
asked Oct 3, 2014 in Embedded Devices by david.lockyer New to the Community (15 points)

Please log in or register to answer this question.

1 Answer

+1 vote
Best answer
you need to add -lpthread or -pthread to the list of compilation switches
answered Oct 10, 2014 by LeonidM Veteran of the Digi Community (4,457 points)
selected Oct 13, 2014 by david.lockyer
Hi Leonid,

That is basically the problem; I can configure Geany to include that switch, building for the local machine, but in the Eclipse Autotools C project I don't know where to begin.

I have tried adding the switch to the CFLAGS variable, but no joy..
I also tried adding the switch in the project>properties>AutotoolsConfigure Settings>Advanced>Additional command-line options...


Having played some more while writing this I edited both the:
Autotools>Configure Settings>autogen>command to include the -pthread switch before the --sysroot
and the:
Autotools>Configure Settings>configure>command to include the -pthread switch before the --sysroot.

And that did the job.. I had expected changes made to the CFLAGS variable to be automatically used to build the command string?

Anyway thanks for the response, it prompted me to have a fresh look and get it working!