我必须对线程执行2次cmake命令

问题描述 投票:0回答:1

我在第一个命令“ cmake”时遇到以下错误。但是如果我做“ cmake”。再次。我可以用makefile编译。我的意思是我必须做两次“ cmake”。命令为什么会发生这样的错误。为什么我需要做“ cmake”。命令然后工作?我该如何解决?那么这个问题可以在windows下发生吗? (我正在使用Ubuntu)

CMakeFiles/exe.dir/SubTimer.cpp.o: In function `std::thread::thread<SubTimer::SubTimer()::{lambda()#1}>(SubTimer::SubTimer()::{lambda()#1}&&)':
/usr/include/c++/7/thread:122: undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/exe.dir/build.make:146: recipe for target 'exe' failed
make[2]: *** [exe] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/exe.dir/all' failed
make[1]: *** [CMakeFiles/exe.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

“我的CMakeLists.txt”:

cmake_minimum_required(VERSION 3.10)


set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -std=c++14 -std=c++11 -std=c++17 ")


project(437_Hw1)

set(SOURCE_FILES main.cpp SubTimer.cpp TimerEntity.cpp)
add_executable(exe ${SOURCE_FILES})

c++ multithreading makefile cmake pthreads
1个回答
0
投票

我建议您替换行

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -std=c++14 -std=c++11 -std=c++17 ")

with

set(CMAKE_CXX_STANDARD 17)
target_link_libraries(exe pthread)

看看是否有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.