The task of developing libraries is always associated with the concern of binary compatibility with future releases of the library. Here is a nice summary of rules to ensure binary compatibility: http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++
Nonetheless, I wanted to make a simple framework test environment to quickly test out a particular type of change in a library.
~/bincompat/lib $ cat fun.h
-
int fun(int a);
~/bincompat/lib $ cat fun.cc
-
#include "fun.h"
-
-
int fun(int a) {
-
return a*a;
-
}
~/bincompat/lib $ cat Makefile
-
libfun.so.1: fun.o
-
g++ -shared -Wl,-soname,libfun.so -o libfun.so.1 fun.o
-
ln -s libfun.so.1 libfun.so
-
-
fun.o: fun.cc fun.h
-
g++ -fPIC -g -c -Wall fun.cc
-
-
clean:
-
rm -f *.o *.so*
~/bincompat $ cat testfun.cc
-
#include "lib/fun.h"
-
#include <iostream>
-
-
int main() {
-
return 0;
-
}
~/bincompat $ cat Makefile
-
testfun: testfun.cc
-
g++ testfun.cc -o testfun -L./lib -lfun
-
-
clean:
-
rm -f testfun
~/bincompat $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib
~/bincompat $ ./testfun
4
Now lets change the library by adding a variant of the function fun() without breaking compatibility and run our test program again:
~/bincompat/lib $ cat fun.h
-
int fun(int a, int b); // added
-
int fun(int a);
~/bincompat/lib $ cat fun.cc
-
#include "fun.h"
-
-
int fun(int a) {
-
return fun(a, 1); // call the more specific version with default value for the missing param
-
}
-
int fun(int a, int b) {
-
return a*a + b*b;
-
}
~/bincompat $ ./testfun
5
#1 by Ajit on September 27, 2009 - 10:12 pm
How is this a framework to test bin compat?
#2 by therider on September 27, 2009 - 10:31 pm
By framework I meant a quick environment to test if a change will work. This means a minimum series of tasks gathered in one place. I am sure I will look for this article sometime in future when I have to test something in less than 5 minutes.