Symbol from external library not explicitly declared

The following code compiles fine in gfortran and ifort, but fails to compile with pgfortran:

logical function isFoo(bar)
   use libExternal
   implicit none
   
   integer, intent(in) :: bar

   foo = bar .eq. externalBar
end function isFoo

The symbol ‘externalBar’ is from the library libExternal. Of note, external bar (and bar) in the real code is an enum bound to an underlying c lib, defined as

enum, bind(c)
    enumerator :: externalBar = 1
    enumerator :: externalBas = 2
    enumerator :: externalBat = 3
end enum

When I compile this code, I get the error ‘PGF90-S-0038-Symbol, externalBar, has not been explicitly declared’. Why am I getting this error?

To add some detail, if I create a test program like this one, it works fine. However it fails in the real code, where libExternal was separately compiled and installed using libtool. The code clearly finds the mod file, so there’s no issue that I can see with the include path. I can also see the externalBar symbol in externalBar.mod.

Ah, this rabbit hole goes even deeper! If I check for equality with one of the other members of the enum, the problem goes away!! That is, if my function reads like this:


logical function isFoo(bar) 
   use libExternal 
   implicit none 
    
   integer, intent(in) :: bar 

   foo = bar .eq. externalBas
end function isFoo

there is no issue at all! There are no spelling errors. I have checked a million times.

Can you tell me what version of the compiler you are using, and on what platform?

15.5, on linux.

Hi Fadecomic,

Would you be able to send PGI Customer Service (trs@pgroup.com) a reproducible example?

Thanks,
Mat