0

I am trying to build a demo from the Boost::Serialization page:

#include <fstream>

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

class gps_position
{
private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & degrees;
        ar & minutes;
        ar & seconds;
    }
    int degrees;
    int minutes;
    float seconds;
public:
    gps_position(){};
    gps_position(int d, int m, float s) :
    degrees(d), minutes(m), seconds(s)
    {}
};

int main() {
    std::ofstream ofs("filename");

    const gps_position g(35, 59, 24.567f);

    {
        boost::archive::text_oarchive oa(ofs);
        oa << g;
    }

    return 0;
}

But I am getting the following linker errors:

boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
(null): "boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int)", referenced from:
(null): "boost::archive::basic_text_oprimitive<std::__1::basic_ostream<char, std::__1::char_traits<char> > >::~basic_text_oprimitive()", referenced from:
(null): Linker command failed with exit code 1 (use -v to see invocation)

I am using boost 1.53.0 in Mountain Lion and XCode 4.6.2.
I have added the path to the headers (Header Search Paths) and libraries (Library Search Paths) and also added libboost_serialization.dylib in Link Binary with Libraries.

Searching in other threads my problems seems to be that I haven't told the compiler about the static library libboost_serialization.a. How do I do this ? (If this is my problem). I tried added to the Other Linker Flags like so: -lboost_serialization with no result.

Anyone else experienced this problem ?

Thnaks in advance.

Adrian
  • 19,440
  • 34
  • 112
  • 219

1 Answers1

0

Have you got some warnings like this ?

ignoring file your _lib_file_name, file was built for unsupported file format (blah blah blah) which is not the architecture being linked

It you have, try to build boost with a proper configuration.

dr.beep
  • 1
  • 4
  • I believe you should look into http://stackoverflow.com/questions/7361751/c-boost-on-iphone . I had the same problem as you did, and this tip helped me. – dr.beep Jun 13 '13 at 14:17