- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot, that solved the problem. When using the alternative solution, I had to insert an extra underscore:
!DEC$ ATTRIBUTES ALIAS:"_lowercasename" :: routinename
!DEC$ ATTRIBUTES ALIAS:"_lowercasename" :: routinename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
probably better to do
!DEC$ ATTRIBUTES, DECORATE, ALIAS:"lowercasename" :: routinename
without the underscore
Les
!DEC$ ATTRIBUTES, DECORATE, ALIAS:"lowercasename" :: routinename
without the underscore
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree with Les and should have suggested that instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That seemingly only works when I supply an interface. Minimal example:
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
----------------------------------------------^
[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
----------------------------------------------^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the compiler should allow that - I'll ask.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page