Issues getting examples to work

Hello Everyone,

I keep getting stuck implementing libraries on the beagle bone black. I want to use “pthread.h”, but I keep getting errors saying that the functions are undefined. I believe I do not have pthread linked to the gcc. Is this correct? How do I do this?



#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void* func1(void* arg)	{
	int i1;
	while(1)	{
		printf("\nthread1 i1=%d, \t1",i1);

void* func2(void* arg)	{
	int i2;
	while(1)	{
		printf("\nthread2 i2=%d, \t\t2",i2);


void testThread()	{
	pthread_t ptid1, ptid2;

	pthread_create(&ptid1, NULL, &func1, NULL);	
	pthread_create(&ptid2, NULL, &func2, NULL); 
	pthread_join(ptid1, NULL);
	pthread_join(ptid2, NULL);


int main()	{
	return 0;


Compiling /var/lib/cloud9/BeagleBone/Black/Thread.c ...
cc     Thread.c   -o Thread
/usr/bin/ld: /tmp/ccX8byyR.o: in function `func1':
Thread.c:(.text+0x10): undefined reference to `pthread_detach'
/usr/bin/ld: /tmp/ccX8byyR.o: in function `func2':
Thread.c:(.text+0x3c): undefined reference to `pthread_detach'
/usr/bin/ld: /tmp/ccX8byyR.o: in function `testThread':
Thread.c:(.text+0x68): undefined reference to `pthread_create'
/usr/bin/ld: Thread.c:(.text+0x76): undefined reference to `pthread_create'
/usr/bin/ld: Thread.c:(.text+0x80): undefined reference to `pthread_join'
/usr/bin/ld: Thread.c:(.text+0x8a): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: Thread] Error 1


Cloud9 is no longer being maintained from what I heard. People are using some other type of instance at port 3000 w/ the newer images.

This could be the reason. Also, when using the already configured source, maybe building them using gcc has a particular way for it to be built.

gcc MyFile.c -o MyFile or if you have to link them, please link them first.

For instance, are you using a Static or Dynamic lib. when compiling?

This may be a precursor to finding out how to manage the compilation w/ gcc.

export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH might help but w/out knowing what type of lib. you are using, I am in the dark.


P.S. Please let me know what compilation steps you have taken, if you are using a Static or Dynamic lib, and then please let me know about the exporting of the lib. using LD.

1 Like

The issue was that I didn’t link the library properly. It worked immediately when I used the
gcc MyFile.c -o MyFile
structure. Is there a way that I can automatically choose the linker files that are attached?

Thanks again for the clear explanation.


1 Like

Hello @Randy_S ,

I think there is a linker/build script in the Cloud9 IDE called beagle-something. So, when testing source, use that compilation tool.


P.S. Outside of that, I am glad you got it to work.