[CMake] undefined reference to 'pthread_create'

Rolf Eike Beer eike at sf-mail.de
Thu Feb 4 15:58:33 EST 2016


Am Donnerstag, 4. Februar 2016, 10:53:37 schrieb rpelapur at archlinux.info:
> I believe that doesn't have anything to do with C11 flags. You are just
> missing the link to the pthread library. I could be wrong.
> 
> Try and add this to your cmake file:
> find_package (Threads)

First:

> set(THREADS_PREFER_PTHREAD_FLAG TRUE)

Always set this if you don't need to be backwards compatible to some obscure 
old CMake code.

If you _need_ threads:

> find_package (Threads REQUIRED)

If it is not required, but optional, check THREADS_FOUND afterwards.

If you can require a CMake >= 3.1:

> target_link_libraries(mything Threads::Threads)

Eike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160204/9ec340d1/attachment.sig>


More information about the CMake mailing list