Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9881 Discussions

pthread on edison - undefined reference to symbol?

CBrou1
New Contributor I
1,441 Views

I am using the Eclipse IDE.

I have been trying to use the pthread library and I am getting a linker error:

... undefined reference to symbol 'pthread_create@@GLIBC_2.1'

(i have tried on two different eclipse installations on two different machines with the same result)

Any idea ?

...

1 Solution
Carlos_M_Intel
Employee
298 Views

Hi CABrouwers,

Which Eclipse IDE version are you using?

Which code are you using?

Could you post a screenshot of the entire error message?

I'm using Eclipse Version: Luna SR2 (4.4.2) (Help > About Eclipse Platform)

Edison image version: 159.devkit (configure_edison --version)

I'm using the following example and had no problems:

# 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; 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);

}

}

/* Last thing that main() should do */

pthread_exit(NULL);

}

Then I added the linker flag –pthread. By doing right click on the project > Properties > C/C++ Build > Settings > Cross GCC Linker > Miscellaneous and adding –pthread on Linker flags. After this, click on Apply and OK.

Let me know if this works for you.

Regards,

Charlie

View solution in original post

3 Replies
Carlos_M_Intel
Employee
299 Views

Hi CABrouwers,

Which Eclipse IDE version are you using?

Which code are you using?

Could you post a screenshot of the entire error message?

I'm using Eclipse Version: Luna SR2 (4.4.2) (Help > About Eclipse Platform)

Edison image version: 159.devkit (configure_edison --version)

I'm using the following example and had no problems:

# 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; 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);

}

}

/* Last thing that main() should do */

pthread_exit(NULL);

}

Then I added the linker flag –pthread. By doing right click on the project > Properties > C/C++ Build > Settings > Cross GCC Linker > Miscellaneous and adding –pthread on Linker flags. After this, click on Apply and OK.

Let me know if this works for you.

Regards,

Charlie

CBrou1
New Contributor I
298 Views

Thanks for response.

I copies the code in a new project and set the linker flag as you indicated.

Now, I get the following error message:

The program file specified in the launch configuration does not exist

C:\Users\xxxxxx\workspace_iot\Testhread\Debug\Testhread not found

I will do further test later ... but perhaps you have idea now ?

Happy New Year !

CBrou1
New Contributor I
298 Views

Finally, I got it to work ! It took me a little while though.

In order to avoid making a spelling error, i was copying the -pthread flag from your post.

When I built I would get a pop up error message:

The program file specified in the launch configuration does not exist

C:\Users\xxxxx\workspace_iot\test\Debug\test not found

However, when I typed -pthread myself, everything turned out fine !

I assume was unknowingly copying some hidden characters that confused the linker!

(probably something that should be fixed in Eclipse)

Thanks a lot for your help!

Reply