Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.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
包含boost/thread.hpp时发生编译错误 我尝试使用C++中的线程,使用Boost的线程库。叮当声给了我一个错误,我不知道如何解释它。我试图编译的文件大约是最小的: #include <iostream> #include <boost/thread.hpp> using namespace std; int main() { return 0; } #包括 #包括 使用名称空间std; int main(){ 返回0; }_C++_Boost_Clang - Fatal编程技术网

包含boost/thread.hpp时发生编译错误 我尝试使用C++中的线程,使用Boost的线程库。叮当声给了我一个错误,我不知道如何解释它。我试图编译的文件大约是最小的: #include <iostream> #include <boost/thread.hpp> using namespace std; int main() { return 0; } #包括 #包括 使用名称空间std; int main(){ 返回0; }

包含boost/thread.hpp时发生编译错误 我尝试使用C++中的线程,使用Boost的线程库。叮当声给了我一个错误,我不知道如何解释它。我试图编译的文件大约是最小的: #include <iostream> #include <boost/thread.hpp> using namespace std; int main() { return 0; } #包括 #包括 使用名称空间std; int main(){ 返回0; },c++,boost,clang,C++,Boost,Clang,以下是成绩单: $ clang++ -std=c++11 -o 4.4 4.4.cpp -v Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.1 Thread model: posix "/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrela

以下是成绩单:

$ clang++ -std=c++11 -o 4.4 4.4.cpp -v
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name 4.4.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 134.9 -v -resource-dir /usr/bin/../lib/clang/4.1 -fmodule-cache-path /var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/clang-module-cache -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/thinkpad20/Documents/workspace/cpp/homework4 -ferror-limit 19 -fmessage-length 100 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/4-49j8fE.o -x c++ 4.4.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin12.2.1
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.2.1
 /usr/include/c++/4.2.1/backward
 /usr/bin/../lib/clang/4.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o 4.4 /var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/4-49j8fE.o -lstdc++ -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init3 in 4-49j8fE.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init1 in 4-49j8fE.o
      ___cxx_global_var_init2 in 4-49j8fE.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$clang++-std=c++11-o4.4.4.cpp-v
Apple clang版本4.1(tags/Apple/clang-421.11.66)(基于LLVM 3.1svn)
目标:x86_64-apple-darwin12.2.1
线程模型:posix
“/usr/bin/clang”-cc1-triple x86_64-apple-macosx10.8.0-emit obj-mrelax all-disable free-disable llvm verifier-main file name 4.4.cpp-pic level 1-mdisable fp elim-released aliasing-masm verbose-munwind tables-target cpu core2-target linker version 134.9-v-resource dir/usr/bin/./lib/clang/4.1-fmodule缓存路径/var/folders/mt/k4dhhm7d7_7_q6drl3zkjj4r0000gn/T/clang模块缓存-std=c++11-fdeprecated宏-fdebug编译目录/Users/thinkpad20/Documents/workspace/cpp/homework 4-ferror limit 19-fmessage length 100-stack protector 1-mstackreallign-fblocks-fobjc运行时有弧-fobjc运行时有弱-fobjc调度方法=混合- FOBC++缺省合成属性-FCXX异常-FExcExt- FCudithToice选项-FCuor诊断-O/Va/文件夹/Mt/K4DHM7D7Y77YQ6DL3ZKJJ4R000 GN/T/4-49 J8FE.O-XC+4.4.CPP
clang-cc1版本4.1基于LLVM 3.1svn默认目标x86_64-apple-darwin12.2.1
忽略不存在的目录“/usr/include/c++/4.2.1/i686-apple-darwin10/x8664”
忽略不存在的目录“/usr/include/c++/4.0.0”
忽略不存在的目录“/usr/include/c++/4.0.0/i686-apple-darwin8/”
忽略不存在的目录“/usr/include/c++/4.0.0/backward”
忽略不存在的目录“/usr/local/include”
#包括“…”搜索从这里开始:
#包括搜索从这里开始:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/bin/。/lib/clang/4.1/include
/usr/包括
/系统/库/框架(框架目录)
/库/框架(框架目录)
搜索列表结束。
“/usr/bin/ld”-demangle-dynamic-arch x86_64-macosx_version_min 10.8.0-o 4.4/var/folders/mt/k4dhhm7d7_7_q6drl3zkj4r0000gn/T/4-49j8fE.o-lstdc++-lSystem/usr/bin/。/lib/clang/4.1/lib/darwin/libclang_rt.osx.a
架构x86_64的未定义符号:
“boost::system::system_category()”,引用自:
___4-49j8fE.o中的cxx_全局_var_init3
“boost::system::generic_category()”,引用自:
___4-49j8fE.o中的cxx全局变量初始化1
___4-49j8fE.o中的cxx_全局_var_init2
ld:找不到架构x86_64的符号
叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用)

感谢您的帮助!:)

您需要告诉clang要链接哪些库。在您的例子中,这是
boost\u系统
(这是错误消息告诉您的)和(一旦您真正开始在程序中使用一些线程材料)
boost\u线程
,因此请按如下方式编译它:


clang++-std=c++11-o myapp myfile.cpp-lboost_system-lboost_thread

链接正确吗?@Rapptz不,他没有-clang调用的
ld
命令在上面的日志中<代码>boost_系统(可能还有
boost_线程
)必须链接才能正常工作。
clang++-std=c++11-o 4.4.4.cpp-v
不够:)