Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;CodeLite是否启用多线程?_C++_Multithreading_Stdthread_Codelite - Fatal编程技术网

C++ C++;CodeLite是否启用多线程?

C++ C++;CodeLite是否启用多线程?,c++,multithreading,stdthread,codelite,C++,Multithreading,Stdthread,Codelite,当我试图编译任何在CodeLite中使用多线程的程序时,我遇到了一点奇怪的行为 我得到一个错误: terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not premitted. 在快速搜索之后,我发现我必须在编译器选项中添加“-pthread” 注意:CodeLite将-l放在库的前面

当我试图编译任何在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;
}
#包括
#包括
#包括
无效测试()
{

std::cout您正在编译器选项中传递
-pthread
。您需要传递它 在“链接器选项”和“链接器选项”中,您不需要 将
pthread
指定为库。
-pthread
选项表示 在这个平台上做任何链接posix线程库的事情


您正在IDE中链接到pthread?我使用:
-pthread-lpthread-Wl,--no-as-needed
。您的命令行有
-lpthread
,但是您的IDE屏幕截图没有显示链接器选项。@Brandon啊,很抱歉,我也在链接
-lpthread
我会做一个快速编辑。我已经尝试了
-Wl,--no-as-needed
作为编译还有r选项?也许我放错地方了?太好了!谢谢,我很高兴它这么简单!
$ g++ -c -O0 -std=c++11 -o main.o main.cpp
$ g++ -o threadtest -pthread main.o
$ ./threadtest
 Look it works!