Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.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/5/spring-mvc/2.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++;std::this_线程::针对编译器错误(叮当声)的睡眠_C++_Clang++ - Fatal编程技术网

C++ c++;std::this_线程::针对编译器错误(叮当声)的睡眠

C++ c++;std::this_线程::针对编译器错误(叮当声)的睡眠,c++,clang++,C++,Clang++,编译时使用:clang++main.cpp-o main.exe-g-std=c++1z--target=x86_64-w64-mingw32 告诉我这个错误: std::this_thread::sleep_for(std::chrono::milliseconds(1000)); C:\Users\this\AppData\Local\Temp\main-124cc2.o:在函数“void std::this\u thread::sleep\u for(std::chrono::durat

编译时使用:
clang++main.cpp-o main.exe-g-std=c++1z--target=x86_64-w64-mingw32

告诉我这个错误:

std::this_thread::sleep_for(std::chrono::milliseconds(1000));
C:\Users\this\AppData\Local\Temp\main-124cc2.o:在函数“void std::this\u thread::sleep\u for(std::chrono::duration const&)”中:
C:\mingw-w64\mingw64\lib\gcc\x86_64-w64-mingw32\6.2.0\include\C++/thread:322:对“nanosleep”的未定义引用
clang++.exe:错误:链接器命令失败,退出代码为1(使用-v查看调用)

发生了什么事?

使用std::this\u线程::sleep\u for(std::chrono::毫秒(1000))‌​;

我认为,您需要添加
-lpthread
,它才能工作。这是一个链接器错误,不是编译器错误。谢谢,它用
-pthread
解决了。奇怪的是,我不记得以前使用过这个编译器选项。。。
C:\Users\this_\AppData\Local\Temp\main-124cc2.o: In function `void std::this_thread::sleep_for<long long, std::ratio<1ll, 1000ll> >(std::chrono::duration<long long, std::ratio<1ll, 1000ll> > const&)':
C:\mingw-w64\mingw64\lib\gcc\x86_64-w64-mingw32\6.2.0\include\c++/thread:322: undefined reference to `nanosleep'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)