c++ - 网络 bean : Adding "Compile Line - Additional Options" "-lboost_system" at the end of compile command

标签 c++ boost netbeans compiler-options

我正在使用 Netbeans 作为 IDE,并且一直在尝试构建一段使用 boost 库的代码,但我遇到了以下错误

g++ -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/tcpproxy_server.o.d" -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: 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: In function 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: In function 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: In function boost::thread_exception::thread_exception(int, char const*)': /usr/include/boost/thread/exceptions.hpp:51: undefined reference toboost::system::system_category()' collect2: error: ld returned 1 exit status

所以我做了一些在线搜索错误,发现我必须在我的编译命令中添加“-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: In function 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: In function 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: In function boost::thread_exception::thread_exception(int, char const*)': /usr/include/boost/thread/exceptions.hpp:51: undefined reference toboost::system::system_category()' collect2: error: ld returned 1 exit status

我发现我必须在编译行的末尾添加它,例如:

"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 以在最后添加我的选项吗?

最佳答案

所以,我做了更多的搜索,发现了一个问题有点像我的问题

文章链接:

C++ Boost on linux via Netbeans remote developement: undefined reference to boost::filesystem::path::codecvt()

这表示我可以使用以下方式链接库:

Project Properties > Linker > Libraries > Add Library > Select the .a files.

这在一定程度上解决了我的问题,我现在尝试成功了:

g++ -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/tcpproxy_server.o.d" -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 -lboost_system

但我仍然不确定这是否是正确的方法,或者为什么在编译器选项之外添加它不起作用。

关于c++ - 网络 bean : Adding "Compile Line - Additional Options" "-lboost_system" at the end of compile command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35816552/

相关文章:

c++ - 十六进制值为 "\3"的动态字符串

c++ - Qt:将 native 操作系统特定代码添加到项目

java - 从数据库中获取数据后 jTable 不显示任何内容

java - 以矩阵形式显示我的输出

java - 如何分析和理解 Java Web 应用程序的输出

c++ 链接器错误 'relocation R_X86_64_32 against ` .rodata.str1.1' Linking CXX shared library libsrt.so

c++ - SDL OpenGL 纹理丢失

c++ - BOOST_FOREACH 在使用 "break"时进入无限循环?

c++ - 使用 boost::thread 开始/停止记录数据(第二次更新)

c++ - Boost序列化断言失败