我有一个类似于C++ Threads之前的错误 ,std :: system_error - 不允许操作?
我正在使用完全相同的源代码并进行编译
g++ ../src/main.cpp -pthread -std=c++11
Run Code Online (Sandbox Code Playgroud)
工作没有任何问题.
因为我想在更大的项目中使用线程,所以我必须使用CMake的线程.在搜索解决方案后,我发现了几个代码,例如:
cmake_minimum_required (VERSION 2.6)
project (Test)
add_definitions("-std=c++11")
find_package (Threads)
add_executable (main src/main.cpp)
target_link_libraries (main ${CMAKE_THREAD_LIBS_INIT})
Run Code Online (Sandbox Code Playgroud)
但对我而言,我总是这样做不起作用:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)
我的错是什么?
CMake输出看起来很有希望:
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working …Run Code Online (Sandbox Code Playgroud)