Boost logo

Boost :

Subject: [boost] Checking library binary compatibility with respect to compile time options
From: joel falcou (joel.falcou_at_[hidden])
Date: 2010-08-04 17:04:14


I was pondering how to event or at least warn users when they use a .a
compiled with a set of define with an
application compiled with divergent options (like having different -D
that may cause ODR violation).

On IRC, I was linked to this page for MSVC 10:

http://msdn.microsoft.com/en-us/library/ee956429.aspx

That defiens some pragma that exactly do that.
However, it's MSVC 10 specific.

After a few brainstorming, we ended up with a simple solution to emulate
this.
The code source is here:

http://dl.dropbox.com/u/3819406/lib_check.tar.gz

Here is a use case:

g++ -c foo.cpp -o foo.o -I/usr/local/include/boost-1_43 -DGOOD_LIB
g++ -c main.cpp -o bmain.o -I/usr/local/include/boost-1_43 -DBAD_LIB -I./
g++ -c main.cpp -o gmain.o -I/usr/local/include/boost-1_43 -DGOOD_LIB -I./

Here, we compiel foo with some settings and try to link it with two
different setup for main.o
The gcc output, showing the divergence in option is detected:

g++ bmain.o foo.o -o bmain
bmain.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x2a): undefined reference to
`boost::config::test_library_version_mismatch_with_version_being_2()'
collect2: ld returned 1 exit status

Of course, when you link the good pair of .o :
g++ gmain.o foo.o -o gmain

Nothing happens

I guess some details need to be hammered out like visibility and such
but could this be a valuable addition to boost (liek boost config for
example)
or have I overengineered something useless ?

Regards


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk