当我跑步时,制作'使用我的NetBeans生成的Makefile,一切都编译好,但是当我们尝试将所有内容链接在一起时,我们得到一个错误:
g++ -o dist/Debug/GNU-Linux-x86/hub build/Debug/GNU-Linux-x86/Calculations.o build/Debug/GNU-Linux-x86/Client.o build/Debug/GNU-Linux-x86/Connection.o build/Debug/GNU-Linux-x86/DataStore.o build/Debug/GNU-Linux-x86/Hub.o build/Debug/GNU-Linux-x86/Instruments.o build/Debug/GNU-Linux-x86/Parameters.o build/Debug/GNU-Linux-x86/PricingEngine.o build/Debug/GNU-Linux-x86/Server.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/stdafx.o -L/usr/lib/x86_64-linux-gnu ../Core/dist/Debug/GNU-Linux-x86/libcore.a -pthread -lpq -lzmq -lboost_system -lboost_log -lboost_log_setup -lboost_thread -lboost_filesystem -lboost_unit_test_framework -lQuantLib
build/Debug/GNU-Linux-x86/Connection.o: In function `Hub::Connection::ReadHeaderHandler(boost::system::error_code, unsigned long)':
/home/jj5/arena/Hub/Connection.cpp:35: undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
/home/jj5/arena/Hub/Connection.cpp:35: undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
/home/jj5/arena/Hub/Connection.cpp:42: undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
/home/jj5/arena/Hub/Connection.cpp:42: undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
问题似乎是缺少提升日志库。但奇怪的是,如果我删除了Boost分片对象文件:
root@happiness:/usr/lib/x86_64-linux-gnu# archive libboost_*.so
Archive path is: /root/archive/2015-09-08-200813
Date: Tuesday 8 September 20:08:13 AEST 2015
User: root
Host: happiness
Path: /usr/lib/x86_64-linux-gnu
File: libboost_atomic.so libboost_chrono.so libboost_context.so libboost_date_time.so libboost_filesystem.so libboost_graph_parallel.so libboost_graph.so libboost_iostreams.so libboost_locale.so libboost_log_setup.so libboost_log.so libboost_math_c99f.so libboost_math_c99l.so libboost_math_c99.so libboost_math_tr1f.so libboost_math_tr1l.so libboost_math_tr1.so libboost_mpi_python-py27.so libboost_mpi_python-py34.so libboost_mpi_python.so libboost_mpi.so libboost_prg_exec_monitor.so libboost_program_options.so libboost_python-py27.so libboost_python-py34.so libboost_python.so libboost_random.so libboost_regex.so libboost_serialization.so libboost_signals.so libboost_system.so libboost_thread.so libboost_timer.so libboost_unit_test_framework.so libboost_wave.so libboost_wserialization.so
然后下次我运行make make compiles and links成功!然而,删除共享对象文件似乎有点激烈......还有其他方法吗?
P.S。 '档案'上面显示的脚本'删除'通过将文件移至'垃圾桶,它类似于rm -rf。
答案 0 :(得分:1)
要使链接器更喜欢静态库,您可以尝试:
-Wl,-Bstatic -lboost_log -lboost_log_setup -Wl,-Bdynamic
注意:
我没有看到直接链接到.a的问题,它没有上述解决方案那么便携
看起来Boost.Log无法在这些符号上设置默认可见性,因此请确保报告此问题。