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


My simple hello world program fails to build with:

undefined reference to `pthread_create’


#define NUM_THREADS	5

void *PrintHello(void *threadid)
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!
", tid);

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
", t );
		rc = pthread_create( &threads[t], NULL, PrintHello, ( void * )t );
		if ( rc )
			printf("ERROR; return code from pthread_create() is %d
", 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!

you need to add -lpthread or -pthread to the list of compilation switches

1 Like

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!