cmake error: undefined reference to `pthread_create'

2,914 views
Skip to first unread message

Junjie Shi

unread,
Jun 7, 2018, 2:34:24 AM6/7/18
to MathGL
When I am trying to install the latest MathGL 2.4.2.1 on Ubuntu 16,
firstly, I run 'cmake .', however, it returns the error message:  
CMakeFiles/cmTC_397db.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

It seems that there is no pthread lib under Ubuntu.
Is there any solution for that error?
Thanks in advance if someone can help me to solve this problem.

D Haley

unread,
Jun 7, 2018, 6:12:58 AM6/7/18
to mat...@googlegroups.com
Hi Junjie,

(Replying to list this time...)

Almost certainly pthread is present on your system. You can use apt-file
to find out where the libpthread.so file is (the library)

$ apt-file find libpthread.so
libc6: /lib/x86_64-linux-gnu/libpthread.so.0

The above path for me is in my default linker path, so it is sufficient
to ensure that your linking flags include "-lpthread" (check LDFLAGS, or
modify cmakelists.txt - ensure you delete CMakecache.txt for it to take
effect (occasionally this is not sufficient)) , in order for this to work.

Alternatively you could disable pthreads entirely, by ensuring that
pthread support is disabled.


option(enable-pthread "Enable POSIX threads support" OFF)

And ensure you don't set enable-pthr-widget or enable-pthread in some
other manner.

Junjie Shi

unread,
Jun 7, 2018, 6:18:26 AM6/7/18
to mat...@googlegroups.com
Hi Haley,

Thanks a lot for your answers.
I can also find the path of the libpthread.so as yours.
I also searched for the solutions from Google, that I need to add the '-Ipthread'  some where.
However, I don't know where to add the '-Ipthread' in the cmakelists.txt.
Could you please tell me where should I put this flag?

D Haley <my...@gmx.com> 于2018年6月7日周四 下午12:12写道:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Best wishes!
Junjie

D Haley

unread,
Jun 7, 2018, 6:22:48 AM6/7/18
to mat...@googlegroups.com, Junjie Shi
Hi Junjie,

Your information is not right - the flag you want is -l, not -I. The
flags are for your compiler (i.e. GCC).

From the gcc manpage:

-I dir
Add the directory dir to the list of directories to be searched for
header files. Directories named by -I are searched before the standard
system include directories.

-llibrary
Search the library named library when linking. (The second alternative
with the library as a separate argument is only for POSIX compliance and
is not recommended.)

You need to modify your library flags.
https://stackoverflow.com/questions/11783932/how-to-add-linker-or-compile-flag-in-cmake-file

--Dan

Junjie Shi

unread,
Jun 7, 2018, 7:44:42 AM6/7/18
to my...@gmx.com, mat...@googlegroups.com
Thanks a lot, it works for me!

D Haley <my...@gmx.com> 于2018年6月7日周四 下午12:22写道:


--
Best wishes!
Junjie
Reply all
Reply to author
Forward
0 new messages