[英]C++ CodeLite Enable Multithreading?
当我尝试编译任何在 CodeLite 中使用多线程的程序时,我遇到了一些奇怪的行为。
我收到错误:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not premitted.
经过一些快速的谷歌搜索后,我发现我必须在编译器选项中添加“-pthread”。
注意:CodeLite 将 -l 放在库的前面,所以它确实使用了 -lpthread
在我清理并重建项目后,我仍然收到错误消息。 据我所知,构建日志看起来不错?
当我通过命令行手动编译它时,真正令人沮丧的部分出现了,它工作得很好。
我已经搜索过了,但似乎没有一个解决方案对我有用? 也许我在某处错过了一步?
这是我的测试代码。 我还应该注意我使用的是 Ubuntu14.04 和 CodeLite 9.1.0
#include <iostream>
#include <string>
#include <thread>
void test()
{
std::cout << " Look it works! \n";
}
void int main(int argc, char** argv)
{
std::thread thrd_1 = std::thread(test);
thrd_1.join();
return 0;
}
任何帮助将不胜感激!
您正在编译器选项中传递-pthread
。 您需要在链接器选项中传递它,并且在链接器选项中您不需要将pthread
指定为库。 -pthread
选项意味着做任何链接这个平台上的 posix 线程库的事情。
$ g++ -c -O0 -std=c++11 -o main.o main.cpp
$ g++ -o threadtest -pthread main.o
$ ./threadtest
Look it works!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.