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

x64 DLL naming with __imp_

dajum
Novice
1,724 Views

Hi,

I have some code that I'm porting to x64. I have a DLL that in the 32 bit version contains a function label __imp__setversion. Note that there are two underscores before and after the "imp". When I compiled it under the x64 platform, the function seems to be named __imp_setversion, with only a single underscore after "imp". That changes the declaration we need in the source. The 32 bit version needs

!DEC$ ATTRIBUTES DLLIMPORT,ALIAS:'_setversion' :: setversion

While the 64 bit version needs

!DEC$ ATTRIBUTES DLLIMPORT,ALIAS:'setversion' :: setversion

I can't seem to find what is forcing this difference. And I would like to keep the source identical so I would like identical names in the two DLLs.

Any ideas why I'm getting this behavior?

Thanks

Dave

0 Kudos
9 Replies
Steven_L_Intel1
Employee
1,724 Views
This is exactly why we created the DECORATE attribute:

!DEC$ ATTRIBUTES DLLIMPORT,DECORATE,ALIAS:"setversion" :: setversion

As for "why", that's the way Microsoft defined the naming conventions for x64.
0 Kudos
dajum
Novice
1,724 Views

Okay I added the DECORATE attribute (code looks like your sample), but it gives an error:

: Error: Only a function or subroutine subprogram may have the !DEC$ ATTRIBUTES directive DECORATE specifier. [SETVERSION]

I'm not sure what it is looking for now.

I went through the help files. Doesn't seem to mention X64 so it is pretty hard to figure out what is supposed to happen.

Thanks,

Dave

0 Kudos
Steven_L_Intel1
Employee
1,724 Views
Which compiler version are you using? Is there an EXTERNAL or interface block declaration for SETVERSION?
0 Kudos
Steven_L_Intel1
Employee
1,724 Views
My apologies - the DECORATE attribute needs to be within an interface block. For example:

program main
interface
subroutine setversion
!DEC$ ATTRIBUTES DLLIMPORT,DECORATE,ALIAS:"setversion" :: setversion
end subroutine
end interface
call setversion
end

The error message is confusing - I'll ask about that.
0 Kudos
dajum
Novice
1,724 Views

Now I'm really confused. I have another routine that is decorated the same way yet I get an error that it is looking for __imp__? Here is my interface

interface

subroutine setversion( str )

Character *(*)str

!DEC$ ATTRIBUTES DLLIMPORT,DECORATE :: setversion

end subroutine

subroutine getVersion( int1,int2 )

Integer int1,int2

!DEC$ ATTRIBUTES DLLIMPORT,DECORATE,ALIAS: 'getVersion' :: getVersion

end subroutine

end interface

This give the error:

error LNK2019: unresolved external symbol __imp__getVersion referenced in function chklck

But it works fine if I take out the DECORATE. So if DECORATE and ALIAS are used together it appears to add an underscore, but without the ALIAS it doesn't?

Dave

0 Kudos
dajum
Novice
1,724 Views

Which by the way, makes the example you gave me wrong I believe.

Dave

0 Kudos
Steven_L_Intel1
Employee
1,724 Views
DECORATE without ALIAS? Hmm. That really ought to be an error...

When you have ALIAS without DECORATE, the string you give is what is used exactly. No additional decoration is added. When you have ALIAS and DECORATE, the compiler treats what's in ALIAS as a "base", the same as it would for an ordinary routine name, and adds whatever decoration is required for the platform and naming convention in effect.

On 32-bit Windows, with the C convention, that means a leading underscore. On 64-bit Windows, it means no underscore.

I don't know how your DLL routine was built, so I can't comment on what is "right" for you. The example I gave assumes that in the source for "getversion" that no explicit decoration was added to the name.
0 Kudos
dajum
Novice
1,724 Views

On 32-bit Windows, with the C convention, that means a leading underscore. On 64-bit Windows, it means no underscore.

But this is what I'm saying the compiler says is not correct. On x64 I have ALIAS and DECORATE so for

!DEC$ ATTRIBUTES DLLIMPORT,DECORATE,ALIAS: 'getVersion' :: getVersion

The compiler is looking for __imp__getVersion. It is adding an underscore. While

!DEC$ ATTRIBUTES DLLIMPORT,ALIAS: 'getVersion' :: getVersion Only looks for __imp_getVersion.

So DECORATE seems to behave differently depending on ALIAS (which the strange notes in the manual imply, but isn't clear enough for a dummy like me to make sense of).

I'm building for x64 on 32-bit Windows XP. Is this a problem? Does it really understand what platform it is being built for? Something is wrong between what the compiler is doing and what you say should be happening.

Dave


0 Kudos
Steven_L_Intel1
Employee
1,724 Views
You are correct - something is wrong - and I think it is the compiler. I'll report it.

Two options for you right now.

1. Remove the DLLIMPORT. Believe it or not, this will work for routines (but not for imported variables). The ALIAS and DECORATE should be specified as I had them.

2. Use this instead:

!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS : '_setversion' :: setversion
!DEC$ ELSE
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS : 'setversion' :: setversion
!DEC$ ENDIF
0 Kudos
Reply