2
  1. Boost was installed and make by: brew install boost
  2. Added the header path /usr/local/Cellar/boost/1.53.0/include to User Header Search Path
  3. Added the library path /usr/local/Cellar/boost/1.53.0/lib to Library Search Path

main.cpp

#include <fstream>
#include <sstream>
#include <string>
#include "test.cpp"

void test(){
    Test instance(true, 'm', 50, 17.89, "fuzhijie");
    stringstream binary_sstream; 
    boost::archive::binary_oarchive binary_oa(binary_sstream);
    binary_oa << instance;
}

int main(int argc, const char * argv[])
{
    test();
    return 0;
}

When I press CTRL+b, the following error message is shown:

Undefined symbols for architecture x86_64:
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::init()", referenced from:
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::init(unsigned int) in main.o
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::save(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      void boost::archive::save_access::save_primitive<boost::archive::binary_oarchive, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(boost::archive::binary_oarchive&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::basic_binary_oprimitive(std::__1::basic_streambuf<char, std::__1::char_traits<char> >&, bool)", referenced from:
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::binary_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) in main.o
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::~basic_binary_oprimitive()", referenced from:
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::~binary_oarchive_impl() in main.o
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::binary_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone have any suggestions on how to fix this?

JWWalker
  • 22,385
  • 6
  • 55
  • 76
simplexk
  • 21
  • 2
  • `Boost.Serialization` is not a header-only library, you should link the binary (`-lserialization`). – Igor R. Apr 16 '13 at 16:59
  • I had added the libboost-serializtion-mt.dylib to the Link Binary with Librarys, if dont link, there is other error shown. – simplexk Apr 17 '13 at 02:30
  • `dylib` is a dynamic library, you can't link it - it's being loaded at run-time. You should link its import library `boost-serialization-mt.a`. – Igor R. Apr 17 '13 at 06:14

1 Answers1

0

The reason is maybe you have compiler gcc5 or gcc6. And your code has used different compile flag with your boost library. Detail please read this link

If you can recompile all incompatible libs you use, do it with compiler option

-D_GLIBCXX_USE_CXX11_ABI=1

and then rebuild your project. If still can not link, add change project's makefile compiler option to 0.

-D_GLIBCXX_USE_CXX11_ABI=0

======Update=======

The real solution should be install the new boost libraries (v1.62) for gcc6 or gcc5.

Community
  • 1
  • 1
PokerFace
  • 811
  • 2
  • 9
  • 15