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));改为code>。我认为,您需要添加-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)