How to know when to use the .a or .so when linking to Boost?

I wanted to try out the Boost::Serialization library for a project I'm working on. I'm also trying to get used to programming in Linux as well. I set up boost in its default locations. I tried compiling the test file they provide here with the command line arguments they provide and it worked fine. In this example they use the .a file.

Then I went to the Serialization page and tried running one of the serialization demos. I ran basically the same commands, except I swapped out the file names and linked against libboost_serialization.a instead of libboost_regex.a, but I got a bunch of errors. After playing with different options and double checking the directories I finally got it to work by replacing the .a with the .so file.

Just for reference, what finally worked for me was this:

g++ /usr/local/lib/ sertest.cpp -o sertest 

How come for one example I linked against the .a file, and in the other I had to link against the .so?

13.10.2009 18:42:38
Shouldn't you use the -l option, maybe with -L for library search paths instead of specifying the library directly in the command line?
Andrey Vlasovskikh 13.10.2009 18:49:04
In the example given they use $ c++ -I path/to/boost_1_40_0 example.cpp -o example \ ~/boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a so I did the same.
Alex 13.10.2009 18:55:10

Because when linking statically, the order in which you specify the libraries and object files does matter. Specifically, a library must be mentioned after object files that use symbols from it.

15.10.2009 17:13:25
Ah, thanks, that must have been what was causing me problems.
Alex 16.10.2009 00:39:53