A Newbie here. Let me show you my CMakeLists.txt first.
cmake_minimum_required(VERSION 3.19.0)
project(sockets VERSION 0.1.0)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 11)
# Set path where to find python files
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/python/lib)
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
# Find the python files: https://cmake.org/cmake/help/latest/module/FindPython.html
find_package(Python 3.9 COMPONENTS Interpreter Development REQUIRED)
message(STATUS "Python_FOUND=${Python_FOUND}")
message(STATUS "Python_VERSION_MAJOR=${Python_VERSION_MAJOR}")
message(STATUS "Python_VERSION_MINOR=${Python_VERSION_MINOR}")
# Add the executable
add_executable(sockets main.cpp)
#target_include_directories(pythoncpp PUBLIC ${Python_LIBRARY_DIRS}) #OBSOLETE
#message(STATUS "Python_LIBRARY_DIRS=${Python_LIBRARY_DIRS}") #OBSOLETE
target_include_directories(sockets PUBLIC ${Python_INCLUDE_DIRS})
message(STATUS "Python_INCLUDE_DIRS=${Python_INCLUDE_DIRS}")
#target_include_directories(pythoncpp PUBLIC ${Python_RUNTIME_LIBRARY_DIRS}) #OBSOLETE
message(STATUS "Python_LIBRARIES=${Python_LIBRARIES}")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(sockets PRIVATE Threads::Threads)
target_link_libraries(sockets PUBLIC ${Python_LIBRARIES} ws2_32)
# Auto copy the python39.dll to the output folder after building
# add_custom_command(TARGET pythoncpp POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# "${PROJECT_SOURCE_DIR}/python/python39.dll"
# $<TARGET_FILE_DIR:pythoncpp>)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
As you can see I've linked thread to my application 'sockets'.
And here is the code segment of sockets and the error.
std::thread t1(GoPython, membuf);
C:\Projects\fork_ljt_algorithm\sockets\main.cpp:296:26: error: 'thread' is not a member of 'std'
std::thread t1(GoPython, membuf);
^~~~~~
C:\Projects\fork_ljt_algorithm\sockets\main.cpp:296:26: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
C:\Projects\fork_ljt_algorithm\sockets\main.cpp:18:1:
+#include <thread>
C:\Projects\fork_ljt_algorithm\sockets\main.cpp:296:26:
std::thread t1(GoPython, membuf);
^~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\sockets.dir\build.make:76: CMakeFiles/sockets.dir/main.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/sockets.dir/all] Error 2
mingw32-make.exe: *** [Makefile:110: all] Error 2
Of course, I've included thread header in the beginning of my program as #include <thread>
.
Can anyone tell me what I'm missing from calling std::thread?