0
votes

I have a very simple class, which I will send as Object via TCP using Asio by boost. I found many examples on the Internet, but when I compile my code I get a Link Failure.

#include <boost/archive/text_oarchive.hpp>


void async_write(){
 std::ostringstream archive_stream;
 boost::archive::text_oarchive archive(archive_stream); // here it fails
 //....
}

I downloaded boost via macports.

My Qt project file:

INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib
LIBS += -lboost_system-mt -lboost_filesystem-mt -lboost_serialization-mt

Failure:

Undefined symbols for architecture x86_64: "boost::archive::text_oarchive_impl::save(std::string const&)", referenced from: void boost::archive::save_access::save_primitive(boost::archive::text_oarchive&, std::string const&) in tcpsession.o "boost::archive::text_oarchive_impl::text_oarchive_impl(std::ostream&, unsigned int)", referenced from: boost::archive::text_oarchive::text_oarchive(std::ostream&, unsigned int) in tcpsession.o "boost::archive::basic_text_oprimitive::~basic_text_oprimitive()", referenced from: boost::archive::text_oarchive_impl::~text_oarchive_impl() in tcpsession.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: * [tcpserver] Error 1

Any help is appreciated.

1
Do simple Boost.Serialization (no asio) examples link for you? If not then likely because Serialization is not header only, so you have to build that library and link it to your program for using it.Öö Tiib
Does libboost_serialization-mt.a actually exist on the linker path?Igor R.
ok i use simple Boost Serialization. boost is building automatically after download from ports. i had include libboost_serialization-mt.a in qt creator in menu add external lib... but the problem is the same. the simple code boost::archive::text_oarchive archive(std::cout); could´t compile. What do i wrong?Max3579
in eclipse there are no problems...Max3579
Side note: Unless you're using the version of Qt that came with MacPorts, you're in for a world of hurt if you have a MacPorts qt4-mac package installed as well - as MacPorts headers will come before the headers for the Qt you use with your project.Kuba hasn't forgotten Monica

1 Answers

0
votes

The standard reply would be "re-run qmake". It's even simpler to just delete the entire shadow build directory. One level up from the source of your project, there will be build-... folders. Delete all of them, and build again.

The simplest way to see whether your project file (the file with LIBS += lines) is current, add something to it that's invalid (like a typo in the library name). If it still "builds" without showing the error directly aimed at your typo (a missing library), then you know that your build is not based on the current project file, and you should re-run qmake or delete the shadow build folder so that everything will be recreated there.