描述
VS2017 使用Visual Studio For Linux远程连接到T家的云服务器上进行开发。
在某个地方用到了C++11标准之后的std::thread
.
编译正常,在运行时遇到了错误:
│terminate called after throwing an instance of 'std::system_error'
│what(): Enable multithreading to use std::thread: Operation not permitted
服务器使用g++编译,版本如下:
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28) │
Copyright (C) 2015 Free Software Foundation, Inc. │
This is free software; see the source for copying conditions. There is NO │
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
解决办法
解决方法很简单,如果不使用vs2017,在编译和链接的同时指定参数-pthread
即可。
例如:
g++ -c main.cpp -pthread -std=c++11 // 编译
g++ main.o -o main.out -pthread -std=c++11 // 链接
如果使用vs2017,那么可以在下述位置添加-pthread
选项。
不要忘记了链接属性也要加入该选项: