简体   繁体   中英

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 to boost::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

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

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

由于我无法重现您的问题,因此我能做的更好的是告诉您我通常如何静态地针对boost_serialization进行编译:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM