[英]Why does my C++ linker only work after I delete boost shared object files?
When I run 'make' using my NetBeans generated Makefile everything compiles OK but then when we try to link everything together we get an error: 当我使用NetBeans生成的Makefile运行“ make”时,一切都编译正常,但是当我们尝试将所有内容链接在一起时,会出现错误:
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()'
The problem seems to be a missing boost logging library. 问题似乎是缺少升压日志记录库。 Curiously, however, if I delete the Boost shard object files:
但是,奇怪的是,如果我删除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
Then the next time I run make everything compiles and links successfully! 然后,下次运行时,一切都将成功编译并链接! Nevertheless, deleting the shared object files seems a little bit drastic... is there some other way?
但是,删除共享对象文件似乎有点麻烦……还有其他方法吗?
ps the 'archive' script shown above 'deletes' files by moving them to 'trash', it's similar to rm -rf. ps上面显示的“存档”脚本通过将它们移到“废纸'”来“删除”文件,它类似于rm -rf。
To make linker prefer a static library, you can try this: 要使链接器更喜欢静态库,可以尝试以下操作:
-Wl,-Bstatic -lboost_log -lboost_log_setup -Wl,-Bdynamic
Notes: 笔记:
I don't see a problem with linking to .a directly, it's not any way less portable than the solution above 我看不到直接链接到.a的问题,它的便携性丝毫不比上面的解决方案低
It would seem Boost.Log fails to set default visibility on these symbols, so please make sure this issue is reported. Boost.Log似乎无法在这些符号上设置默认可见性,因此请确保报告了此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.