Reputation: 23
Background: We're using very old Fortran code (F77) developed originally on VAX/OpenVMS, which allowed for customized linking - i.e. you could define multiple symbols in your library, but were given the ability to force the linker to use a specific symbol.
Using VS2010 and Intel Fortran 2013, I am looking for a way for the linker to force it to use the symbol (i.e. MYSUBROUTINE) from a specific library when it exists in mutiple libraries.
I have a mixed C++/Fortran project. The in-house developed libraries are not my own, so removing the unused subroutine isn't trivial. Hence, why I'm looking for a way to force the VS2010/Intel Fortran 2013 linker to use a specific subroutine.
I imagine this issue isn't unique to us, since many legacy code houses, particularly ones with alot of Fortran, must have this issue.
Upvotes: 1
Views: 226
Reputation: 21441
When searching libraries (.lib), the linker will use the first matching symbol that it finds. Libraries are searched in a well defined order. To have a different library take precedence for a particular symbol, specify the library earlier in the link command line (list it earlier in Linker > Input > Additional Dependencies for the executable project within Visual Studio)
If you have multiple subroutines across multiple libraries that you want chosen, then you will need to use a different approach, such as unpacking the libraries and selecting the object code for the routines that you want as a separate step.
Note that object files take precedence over libraries when searching for symbols.
Multiply defined symbols only applies to symbols within object files (.obj).
Upvotes: 1