Method 1
PROJECT(HELLO)
set(CMAKE_CXX_FLAGS "${CAMKE_CXX_FLAGS} -std=c++11")
AUX_SOURCE_DIRECTORY(. SRC_LIST)
ADD_EXECUTABLE(hello ${SRC_LIST})
From the cmakelists.txt file of cmake, we can see that cmake has – STD = C + + 11, just like G + + uses C + + 11, so we can add – pthread to solve it
PROJECT(HELLO)
set(CMAKE_CXX_FLAGS "${CAMKE_CXX_FLAGS} -std=c++11 -pthread")
AUX_SOURCE_DIRECTORY(. SRC_LIST)
ADD_EXECUTABLE(hello ${SRC_LIST})
Method 2
Using package threads and link ${cmake_ THREAD_ LIBS_ INIT}
PROJECT(HELLO)
set(CMAKE_CXX_FLAGS "${CAMKE_CXX_FLAGS} -std=c++11")
FIND_PACKAGE(Threads)
AUX_SOURCE_DIRECTORY(. SRC_LIST)
ADD_EXECUTABLE(hello ${SRC_LIST})
TARGET_LINK_LIBRARIES(hello ${CMAKE_THREAD_LIBS_INIT})
Similar Posts:
- Undefined reference to ‘pthread’ appears in Linux Ubuntu running thread program_ Create ‘and undefined reference to’ pthread ‘_ ‘join’ error.
- No matching function call to ‘pthread_create’ [How to Solve]
- invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’
- [Solved] Protobuf & cmake Low Version Error: Could not find a package configuration file provided by “Protobuf” with any of the following names: ProtobufConfig.cmake
- Hi3516DV300 Chip Error: “undefined reference to ×”
- Cmake: How to Connect boost Library
- [Solved] LD: library not found for – XXX when Xcode compiles code
- Centos7 Install MYSQL Error: Could NOT find Curses (missing CURSES_LIBRARY CURSES_INCLUDE_PATH)
- CMake: How to Complie Log4cplus