3

I have multiple Fortran static libraries which have functions with the same name, that I'd like to call from Rust. Using objcopy prefixing, I can make the names unique, as shown here:

ld -r obj1.o obj2.o ... objn.o -o static1.o
objcopy --localize-hidden --prefix-symbols=foo static1.o static2.o
ar -rcs mylib.a static2.o

However, it seems that objcopy prefixes all symbols, even the ones that only appear as a function call to an external library. Thus, I get errors such as:

/usr/bin/ld: (.text+0xaf0c): undefined reference to `foo_gfortran_runtime_error_at'

It seem then that I only want to rename the symbols that are marked as T in nm. Is this correct? Is there a way to do this with objcopy or ld?

Do you also know of a solution that works on Mac as well (where objcopy is unavailable)?

Ben Ruijl
  • 4,973
  • 3
  • 31
  • 44
  • 1
    It would be easier to wrap the code for each static library in a module with a unique name. Fortran compilers typically mangle the names of entities within a module. For example, my Gaussian elimination routines are wrapped in module named gaussm, and the double precision function gauss_dble has the name __gaussm_MOD_gauss_dble in the library. – Steve Aug 07 '19 at 18:32

0 Answers0