Manikandaraj Srinivasan
Manikandaraj Srinivasan

Reputation: 3647

Linker Error : Statically Linking of Boost Serialization Library

I'm trying to link the Boost Serialization Library to my Code. But it doesn't seem to be working.

g++ serialize.cpp -L"/usr/local/lib/libboost_serialization.a"

Error :

/tmp/ccw7eX4A.o: In function boost::archive::text_oarchive::text_oarchive(std::basic_ostream<char, std::char_traits<char> >&, unsigned int)': serializep.cpp:(.text._ZN5boost7archive13text_oarchiveC2ERSoj[_ZN5boost7archive13text_oarchiveC5ERSoj]+0x25): undefined reference toboost::archive::text_oarchive_impl::text_oarchive_impl(std::basic_ostream >&, unsigned int)' .......... collect2: ld returned 1 exit status

But when i link as a shared library, g++ serialize.cpp -lboost_serialization , it works fine.

What am i missing here

P.S : Other StackOverflow posts with the same question has no answers that work for the above error

Upvotes: 0

Views: 2119

Answers (2)

Employed Russian
Employed Russian

Reputation: 213799

g++ serialize.cpp -L"/usr/local/lib/libboost_serialization.a"

This command line is totally wrong: the -L flag tells the linker where to look for libraries; it does not tell the linker to use a library you are giving. Try this instead:

g++ serialize.cpp /usr/local/lib/libboost_serialization.a

Upvotes: 1

Hugo Corr&#225;
Hugo Corr&#225;

Reputation: 14799

Since I can't reproduce your problem, the better I can do is to tell you how I generally compile against boost_serialization statically:

 g++ myapp.cpp -o myapp -Wall -static -static-libgcc -I/usr/local/include -L/usr/local/lib -lboost_serialization -lpthread

Upvotes: 0

Related Questions