我使用Netbeans作为IDE,并一直在尝试构建一段使用boost库的代码,但我得到的错误
g -c -g -MMD -MP -MF“build / Debug / GNU-Linux-x86 / tcpproxy_server.od”-o build / Debug / GNU-Linux-x86 / tcpproxy_server.o tcpproxy_server.cpp mkdir -p dist / Debug / GNU-Linux-x86 g -o dist / Debug / GNU-Linux-x86 / tcp_proxy build / Debug / GNU-Linux-x86 / tcpproxy_server.o build / Debug / GNU-Linux-x86 / tcpproxy_server.o:in function __static_initialization_and_destruction_0(int,int)':/ usr / include / boost / system / error_code.hpp:221:undefined reference toboost :: system :: generic_category()'/ usr /include/boost/system/error_code.hpp:222:对boost :: system :: generic_category()'/usr/include/boost/system/error_code.hpp:223的未定义引用:undefined reference toboost :: system :: system_category()'build / Debug / GNU-Linux-x86 / tcpproxy_server.o:在函数boost :: system :: error_code :: error_code()':/ usr / include / boost / system / error_code.hpp:322:undefined reference toboost :: system :: system_category()'build / Debug /GNU-Linux-x86/tcpproxy_server.o:在函数boost :: asio :: error :: get_system_category()':/ usr / include / boost /asio/error.hpp:230:未定义的引用toboost :: system :: system_category()'build / Debug / GNU-Linux-x86 / tcpproxy_server.o:在函数boost :: thread_exception :: thread_exception(int,char const *) )':/ usr /include/boost/thread/exceptions.hpp:51:未定义引用toboost :: system :: system_category()'collect2:错误:ld返回1退出状态
所以我做了一些在线搜索错误,发现我必须在我的编译命令中添加“-lboost_system” .
我在“project-> properties-> build-> c compiler-> Additional Options”中添加了它,但仍然是同样的错误 .
g -lboost_system -o dist / Debug / GNU-Linux-x86 / tcp_proxy build / Debug / GNU-Linux-x86 / tcpproxy_server.o build / Debug / GNU-Linux-x86 / tcpproxy_server.o:in function __static_initialization_and_destruction_0(int, int)':/ usr /include/boost/system/error_code.hpp:221:undefined reference toboost :: system :: generic_category()'/ usr /include/boost/system/error_code.hpp:222:undefined reference to boost :: system :: generic_category()'/ usr /include/boost/system/error_code.hpp:223:undefined reference toboost :: system :: system_category()'build / Debug / GNU-Linux-x86 / tcpproxy_server.o:在函数boost :: system :: error_code :: error_code()':/ usr /include/boost/system/error_code.hpp:322:undefined reference toboost :: system :: system_category()'build / Debug / GNU-Linux -x86 / tcpproxy_server.o:在函数boost :: asio :: error :: get_system_category()':/ usr / include / boost / asio / error.hpp:230:undefined reference toboost :: system :: system_category()' build / Debug / GNU-Linux-x86 / tcpproxy_server.o:在函数boost :: thread_exception中:: thread_exception(int,char const *)':/ usr /include/boost/thread/exceptions.hpp:51:undefined reference toboost :: system :: system_category()'collect2:error:ld返回1退出状态
我发现我必须在编译行的末尾添加它,例如:
“g tcp_proxy.cpp -o tcpproxy -lboost_system”
我尝试了它的工作,但netbeans在开始时添加“添加选项”
喜欢:
g -lboost_system -o dist / Debug / GNU-Linux-x86 / tcp_proxy build / Debug / GNU-Linux-x86 / tcpproxy_server.o
有什么办法可以配置netbeans来添加我的选项吗?
1 回答
所以,我做了一些搜索,发现了一个问题
链接到帖子:
C++ Boost on linux via Netbeans remote developement: undefined reference to boost::filesystem::path::codecvt()
这说我可以使用以下方式链接库:
这在某种程度上解决了我的问题,我现在尝试成功:
但我仍然不确定如果这是正确的方法或为什么添加它除了编译器选项不起作用 .