简体   繁体   English

为什么我的C ++链接器仅在删除boost共享对象文件后才能工作?

[英]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.

相关问题 为什么C ++ boost包只包含.hpp文件? - Why does the C++ boost package only contain .hpp files? 为什么我的C++ function,只有放在main()之后,不起作用? - Why does my C++ function, only when it's placed after main(), not work? 如果我删除const,为什么调用boost :: shared_ptr不能在c ++中编译? - Why does this call with boost::shared_ptr not compile in c++ if I remove the const? C++ 为什么 linker 看不到我的文件? - C++ Why can't the linker see my files? 为什么我的课程只能与两个构造函数一起使用c ++ - why does my class only work with two constructors c++ 为什么 C++ 链接器在构建过程中需要库文件,即使我是动态链接的? - Why does the C++ linker require the library files during a build, even though I am dynamically linking? 为什么BOOST_FOREACH有时不能用C ++字符串工作? - Why does BOOST_FOREACH not work sometimes with C++ strings? 为什么C ++ Boost发行版有`.dll`和`.lib`文件? - Why does C++ Boost distribution have `.dll`and `.lib` files? 为什么在C ++中使用Boost Filesystem会出现链接器错误? - Why do I get a linker error using the Boost Filesystem in C++? 尝试从使用makefile创建的目标文件进行构建时,C ++链接器错误。 当我刚刚构建它时不会发生 - C++ linker error when trying to build from object files made using makefile. Does not occur when I just build it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM