tags:

views:

523

answers:

2

I'm ruinning on RHEL 5.1 and use gcc.

How I tell cmake to add -pthread to compilation and linking?

+1  A: 

Should be as simple as adding

find_package(PTHREAD)

to your CMakeLists.txt file

Take a look at this link for more details

Glen
Should I do something in case PTHREAD_FOUND?
dimba
+1  A: 

Here is the right anwser:

ADD_EXECUTABLE(your_executable ${source_files})

TARGET_LINK_LIBRARIES(
pthread
)

equivalent to

-lpthread
Nadir SOUALEM
This is equivalent. "-pthread" donates much more - at compilation it's -D_REENTRANT, at link time -lpthread. On some system at even can be more than this.
dimba
SET(CMAKE_CXX_FLAGS_DEBUG "... -lpthread")SET(CMAKE_CXX_FLAGS_RELEASE "... -lpthread")
Nadir SOUALEM