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

2
  • Did you put in -std=c++11 when compiling? Commented Aug 2, 2014 at 9:41
  • @HerpDerpington Yes, I did. I also tried -std=c++0x, but pretty much the same error message was generated. Commented Aug 2, 2014 at 10:01

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

6 Comments

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.
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.
The libraries' names don't have any hints. They're just libboost_signals.a, libboost_signals-mt.a, libboost_thread-mt.a, etc..
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.
When you invoke homebrew try: "brew install address-model=64 boost"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.