Reputation: 115
I am developing a Fortran program prog1
and two Fortran libraries, lib1
and lib2
. prog1
depends on lib1
and lib2
, and lib1
also depends on lib2
. The directory structure might look like:
prog1
|- lib2
|- lib1
|- lib2
In some cases, I would like prog1
to use a different version of lib2
than what lib1
uses. However, if the static library lib1.a
includes the object files from lib2
, the linker gives me errors like
./lib1/lib1.a(lib2_module.o): In function `__lib2_module_MOD_function1':
./lib2/src/lib2_module.f90:12: multiple definition of `__lib2_module_MOD_function1'
./lib2/lib2.a(lib2_module.o):./lib2/src/lib2_module.f90:12: first defined here
In other words, the linker is confused since both libraries contain the same object file lib2_module.o
, but with different versions.
So my question is: How can two Fortran libraries contain (and use) different versions of the same object files?
Upvotes: 5
Views: 487
Reputation: 10165
I do not think it is possible to do it by usage of static libraries. It is because from prog1 prespective, function1 from lib2's module is simple defined 2 times. On Wikipedia you can see that
...external functions and variables which are resolved in a caller at compile-time and copied into a target application...
And you would probably not be suprised that this code would generate similar errors you see in your question:
prog1.f90
some code here...
function funtion1(x) ...
...first version of function1 ...
end function
function funtion1(x) ...
...second version of function1 ...
end function
some code here...
One possibility would be to compile at least lib1 as shared library and make sure (compiler/platform dependent) that the symbols from lib2 are not exported from shared lib1.
Upvotes: 2