0

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:

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:

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?

p.s. the 'archive' script shown above 'deletes' files by moving them to 'trash', it's similar to rm -rf.

John Elliot V
  • 302
  • 2
  • 8
  • Did you try this? http://stackoverflow.com/questions/23137637/linker-error-while-linking-boost-log-tutorial-undefined-references – Gombat Sep 08 '15 at 10:27
  • At [the bottom](http://stackoverflow.com/a/30423984/868138) my options are: link directly to the .a file (system dependent, not an option) or delete the *.so files, which is what I've done. The other options are to dynamically link the boost log components, but I don't want to dynamically link, I want to static link... – John Elliot V Sep 08 '15 at 10:50
  • Do you know cmake? If you want to work on multiplatform projects it might be a good way. – Gombat Sep 08 '15 at 10:52
  • I suppose, boost uses auto linking if no lib files are provided, is this possible? – Gombat Sep 08 '15 at 10:57
  • I use GNU Make 4.0. I'd prefer not to put the .a files in the Makefile... – John Elliot V Sep 08 '15 at 11:17
  • I don't see a workaround, you have to distinguish between the different platforms. – Gombat Sep 08 '15 at 11:20

1 Answers1

1

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

  • It would seem Boost.Log fails to set default visibility on these symbols, so please make sure this issue is reported.

umläute
  • 28,885
  • 9
  • 68
  • 122
Vladimir Prus
  • 4,600
  • 22
  • 31
  • The lack of those symbols on boost.log is because the code isn't compiled with `BOOST_DYN_LINK` but links against the dynamic libraries. – Anya Shenanigans Sep 08 '15 at 12:58
  • The documentation still say BOOST*DYN_LINK macros are Windows-only: http://www.boost.org/doc/libs/1_59_0/libs/config/doc/html/index.html so a bug report is in order either way. – Vladimir Prus Sep 08 '15 at 19:06