gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:19:34 25 4
gpt4 key购买 nike

我正在使用 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 to
boost::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 to
boost::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 to
boost::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 to
boost::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 to
boost::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 to
boost::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 to
boost::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 to
boost::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 to
boost::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 to
boost::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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com