描述
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选项。

不要忘记了链接属性也要加入该选项:

本文介绍了在VS2017中通过远程连接到Linux服务器进行C++开发时遇到的一个多线程问题及解决方案。当使用std::thread时,在运行阶段会报错“Operation not permitted”。解决方法是在编译和链接时加入-pthread参数。
9255

被折叠的 条评论
为什么被折叠?



