Reputation: 1847
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.
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
Upvotes: 0
Views: 747
Reputation: 1621
Check that your boost installation contains libraries compiled for x86_64. You may have 32-bit libraries.
Upvotes: 1