[英]C++ CodeLite Enable Multithreading?
I'm experiencing a bit of strange behaviour when I try to compile any program that uses multithreading in CodeLite.当我尝试编译任何在 CodeLite 中使用多线程的程序时,我遇到了一些奇怪的行为。
I get the error:我收到错误:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not premitted.
after some quick googling I found out I had to add "-pthread" to the compiler options.经过一些快速的谷歌搜索后,我发现我必须在编译器选项中添加“-pthread”。
Note: that CodeLite puts -l in front of libraries, so it does use -lpthread注意:CodeLite 将 -l 放在库的前面,所以它确实使用了 -lpthread
After I clean, and rebuild the project, I still get the error though.在我清理并重建项目后,我仍然收到错误消息。 As far as I can tell the build log looks fine?
据我所知,构建日志看起来不错?
The truly frustrating part comes about when I compile it manually via the command line, It works just fine.当我通过命令行手动编译它时,真正令人沮丧的部分出现了,它工作得很好。
I've searched, but none of the solutions seem to work for me?我已经搜索过了,但似乎没有一个解决方案对我有用? perhaps I've missed a step somewhere?
也许我在某处错过了一步?
here's my test code.这是我的测试代码。 I should also note I'm using Ubuntu14.04, and CodeLite 9.1.0
我还应该注意我使用的是 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;
}
Any help would be greatly appreciated!任何帮助将不胜感激!
You are passing -pthread
in the compiler options.您正在编译器选项中传递
-pthread
。 You need to pass it in the linker options, and in the linker options you do not need to specify pthread
as a library.您需要在链接器选项中传递它,并且在链接器选项中您不需要将
pthread
指定为库。 The -pthread
option means do whatever it is that links the posix threads library on this platform . -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.