0

In an experiment with Boost.Signals2, I tried to compile the following very naive program. The program did compile, but I got a linker error (see the bottom of this question for the error message).

// hello.cpp
#include <boost/signals2.hpp>

int main(int argc, char *argv[])
{
    boost::signals2::signal<void()> sig;
}

Why was there an error and how to fix it?

(Update on 2014-09-17: The issue is still unresolved. The program can be built successfully with GCC4.9 and Code::Blocks on Windows XP or with Clang and Xcode 5 on Mac OS X Mavericks, but for some mysterious reasons, the linking error just doesn't go away when the program is built with GCC4.9 and Eclipse on Mac OS X.)

I have found the following related threads on SO, but none seem to answer my question.

  1. boost::signals2 undefined-reference when linking libraries together
  2. Boost linker errors when using header only libraries
  3. Does the boost.signals2 library need to be built?

Here is the error message:

make all

Building file: ../src/hello.cpp

Invoking: GCC C++ Compiler

/usr/local/bin/g++-4.9 -I/usr/include -I/usr/local/include -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/hello.d" -MT"src/hello.d" -o "src/hello.o" "../src/hello.cpp"

Finished building: ../src/hello.cpp

Building target: hello

Invoking: MacOS X C++ Linker

/usr/local/bin/g++-4.9 -L/usr/local/lib -L/usr/lib -o "hello" ./src/hello.o

Undefined symbols for architecture x86_64:

"std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)", referenced from:

void std::list<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<void (), boost::function<void ()> >, boost::signals2::mutex> >, std::allocator<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<void (), boost::function<void ()> >, boost::signals2::mutex> > > >::_M_insert<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<void (), boost::function<void ()> >, boost::signals2::mutex> > const&>(std::_List_iterator<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<void (), boost::function<void ()> >, boost::signals2::mutex> > >, boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<void (), boost::function<void ()> >, boost::signals2::mutex> > const&) in hello.o

ld: symbol(s) not found for architecture x86_64

collect2: error: ld returned 1 exit status

make: *** [hello] Error 1

Community
  • 1
  • 1
user740006
  • 1,759
  • 4
  • 20
  • 30

1 Answers1

1

Check that your boost installation contains libraries compiled for x86_64. You may have 32-bit libraries.

Brandon Kohn
  • 1,612
  • 8
  • 18
  • Thanks. I installed boost 1.55 using homebrew. How to check that if it was compiled for x86_64? Anyway, I am puzzled: isn't Boost.Signals2 a header-only library? Also, if I used Boost.Signals (for which some libraries have to be built) instead of Boost.Signals2 (header-only), the linker doesn't complain. – user740006 Aug 02 '14 at 11:21
  • I think boost signals2 is meant to be thread-safe, and that would make it dependend on boost thread I suppose. Boost thread isn't header only. As for the version of boost, check the libraries. Their names should have something about the architecture in it. – Brandon Kohn Aug 02 '14 at 23:11
  • The libraries' names don't have any hints. They're just `libboost_signals.a`, `libboost_signals-mt.a`, `libboost_thread-mt.a`, etc.. – user740006 Aug 03 '14 at 10:20
  • I've never used homebrew. I assume you refer to a package manager for linux? I would look at homebrew to see what it installs. – Brandon Kohn Aug 03 '14 at 11:56
  • When you invoke homebrew try: "brew install address-model=64 boost" – Brandon Kohn Aug 03 '14 at 12:02
  • Tried that a couples of hours ago, but with no luck. I wil fall back to other libraries (and/or other compilers/platforms). Thanks very much for your many patient responses. – user740006 Aug 04 '14 at 16:34