gekowa
gekowa

Reputation: 452

Linking 2 libraries with same module name and subroutine name

I'm on a Fortran project, that I have to link 2 libraries who have same module name, under which, have same subroutine name. I'm using Intel Fortran compiler, when I import the module and call the subroutine, it always goes to the first one linked.

Is there a way that I can specifically call a subroutine from a specific library?

Here's some pseudo code:

Lib1 and Lib 2 both have this:

module foo
  subroutine func()
    write (*, *) "Hello from Lib1" ! or Lib2
  end subroutine()
end module

Main

program Main
  use foo, only: func

  call func()
end program

CMakeLists.txt


target_link_libraries(Main PRIVATE libLib1.so libLib2.so)

Upvotes: 2

Views: 347

Answers (1)

It is illegal to have two modules name identically in Fortran. When writing libraries used by other users, I highly recommend to use prefixes such as mylibrary_foo for module names and other entities that might clash.

Now you cannot do much, apart from renaming the stuff. If you want to try to somehow separate the stuff using tricks in your toolchain, you firstly have to specify your toolchain in detail, but I'm sceptical.

Upvotes: 5

Related Questions