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
Einsteiger
1.543Aufrufe
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 Lösung
Steven_L_Intel1
Mitarbeiter
1.543Aufrufe
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.

Lösung in ursprünglichem Beitrag anzeigen

7 Antworten
Steven_L_Intel1
Mitarbeiter
1.544Aufrufe
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.
tom_p
Einsteiger
1.543Aufrufe
Thanks a lot, that solved the problem. When using the alternative solution, I had to insert an extra underscore:

!DEC$ ATTRIBUTES ALIAS:"_lowercasename" :: routinename
Les_Neilson
Geschätzter Beitragender II
1.543Aufrufe
probably better to do
!DEC$ ATTRIBUTES, DECORATE, ALIAS:"lowercasename" :: routinename

without the underscore

Les
Steven_L_Intel1
Mitarbeiter
1.543Aufrufe
I agree with Les and should have suggested that instead.
tom_p
Einsteiger
1.543Aufrufe
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
----------------------------------------------^
Arjen_Markus
Geehrter Beitragender II
1.543Aufrufe
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
Steven_L_Intel1
Mitarbeiter
1.543Aufrufe
I think the compiler should allow that - I'll ask.
Antworten