finding in packages using cmake find_package
GCC 4.6.0
Linux
cmake 2.8
I am using cmake to generate my make file. However, in my network_imp.c
file I need to do some threading. So I have included the header file #include <pthread.h>
and I am using the pthread_create()
function
How can I tell cmake to use this header pthread.h and shared library -lpthread?
I thought about using the find_package, but I don't think I am using it correctly. This is my CMakeLists.txt file.
find_package(pthread)
add_library(network SHARED network_imp.c)
The error I get when I try and make is this:
undefined reference to pthread_create
Many thanks for any sug开发者_Go百科gestions,
In general you should use target_link_libraries
cmake command to link your executables with other libraries. find_package
command is used to set special cmake variables, containing, for example, the actually libraries, to link with.
And for working with pthread
you should use find_package(Threads)
.
And here is the answer to your particular question.
精彩评论