Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

importing lowercase symbols

tom_p
Beginner
1,064 Views
I have a problem linking to a .lib file withthe linker complaining about an unresolved symbol (LNK2019 error). This is, I believe, because the ifort compiler converts all symbols to uppercase, whereas the .lib file contains lowercase symbols. Is there anyway to change this behavior?
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,064 Views
There are multiple ways to do this. What I would recommend is to declare an interface for the routines you're calling and add "BIND(C)" after the argument list. For example:

interface
subroutine sub1 (arg) bind(C)
integer arg
end subroutine

subroutine sub2 (arg) bind(C)
integer arg
end subroutine
...
end interface

The bind(C) will cause the names to be downcased.

An alternative is to use:

!DEC$ ATTRIBUTES ALIAS:"lowercasename" :: routinename

where you'll be calling the routine.

You do not want to force ALL external names to be lowercase - this can lead to other problems.

View solution in original post

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,065 Views
There are multiple ways to do this. What I would recommend is to declare an interface for the routines you're calling and add "BIND(C)" after the argument list. For example:

interface
subroutine sub1 (arg) bind(C)
integer arg
end subroutine

subroutine sub2 (arg) bind(C)
integer arg
end subroutine
...
end interface

The bind(C) will cause the names to be downcased.

An alternative is to use:

!DEC$ ATTRIBUTES ALIAS:"lowercasename" :: routinename

where you'll be calling the routine.

You do not want to force ALL external names to be lowercase - this can lead to other problems.
0 Kudos
tom_p
Beginner
1,064 Views
Thanks a lot, that solved the problem. When using the alternative solution, I had to insert an extra underscore:

!DEC$ ATTRIBUTES ALIAS:"_lowercasename" :: routinename
0 Kudos
Les_Neilson
Valued Contributor II
1,064 Views
probably better to do
!DEC$ ATTRIBUTES, DECORATE, ALIAS:"lowercasename" :: routinename

without the underscore

Les
0 Kudos
Steven_L_Intel1
Employee
1,064 Views
I agree with Les and should have suggested that instead.
0 Kudos
tom_p
Beginner
1,064 Views
That seemingly only works when I supply an interface. Minimal example:

[fortran]program test

  implicit none

  external SUBRT
  !DEC$ ATTRIBUTES DECORATE, ALIAS:"subrt" :: SUBRT

  call SUBRT()
end program test
[/fortran]

test.f90(6) : Error: Only a function or subroutine subprogram may have the !DEC$
ATTRIBUTES directive DECORATE specifier. [SUBRT]
!DEC$ ATTRIBUTES DECORATE, ALIAS:"subrt" :: SUBRT
----------------------------------------------^
0 Kudos
Arjen_Markus
Honored Contributor I
1,064 Views
With just the declaration "external SUBRT"the compiler can not see what kind of external
you have. If you have an explicit interface it can. (Not sure if an ordinary variable can be
declared "external", but I guess COMMON blocks are another example).

Normally, you put these attributes at the definition of the subroutine or function.
Regards,

Arjen
0 Kudos
Steven_L_Intel1
Employee
1,064 Views
I think the compiler should allow that - I'll ask.
0 Kudos
Reply