Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
13 Views

need a little help calling C

I have a DLL I can call from a C program, but not from fortran.  When I build the fortran program, I get unresolved external.

The c prototype for the function is  hasp_status_t HASP_CALLCONV hasp_logout(hasp_handle_t *handle);
hasp_handle_t appears to be unsigned long in C

hasp_status_t appears to be an integer.  It's actually an enum so I think that means it's a regular integer.

HASP_CALLCONV appears to be __stdcall

How do call this from fortran?  I've tried types integer for the return value and c_int32_t for the handle argument, but the linker gives me unresolved external.  I have both the DLL and its corresponding .LIB file which I have included in the visual studio project.

	use, intrinsic :: iso_c_binding 
	implicit none 
	interface
		function hasp_logout(handle) result(retval) bind(C, name="hasp_logout")
			import
			integer(c_int32_t) :: handle
			integer :: retval
		end function
	end interface

 

0 Kudos
38 Replies
Highlighted
Black Belt Retired Employee
13 Views

It would help us help you if you showed us 1) the linker error message, 2) the part of a "dumpbin -exports" for the DLL showing the name of the routine.

You can add:

!DEC$ ATTRIBUTES STDCALL to the interface to make it STDCALL.

0 Kudos
Highlighted
Black Belt
13 Views

When one investigates problems with STDCALL, it is usually helpful to know if we are talking about 32-bit or 64-bit code.

0 Kudos
Highlighted
New Contributor I
13 Views

Thanks for the replies.  It is 32 bit code, and the linker error message is.....

CheckSentinelKey.obj : error LNK2019: unresolved external symbol _hasp_logout referenced in function _CHECKSENTINELKEY
Debug\SentinelFortran.exe : fatal error LNK1120: 1 unresolved externals

Compile and Link command lines are.....

/nologo /debug:full /Od /warn:interfaces /module:"Debug\\" /object:"Debug\\" /Fd"Debug\vc100.pdb" /traceback /check:bounds /check:stack /libs:static /threads /dbglibs /c

/OUT:"Debug\SentinelFortran.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"C:\Users\Brian\Documents\Visual Studio 2010\Projects\SentinelFortran\SentinelFortran\Debug\SentinelFortran.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\Brian\Documents\Visual Studio 2010\Projects\SentinelFortran\SentinelFortran\Debug\SentinelFortran.pdb" /SUBSYSTEM:CONSOLE /IMPLIB:"C:\Users\Brian\Documents\Visual Studio 2010\Projects\SentinelFortran\SentinelFortran\Debug\SentinelFortran.lib"

 

0 Kudos
Highlighted
New Contributor I
13 Views

Dependency walker shows the routine name as hasp_logout all lower case.  When I look inside the .LIB file for the DLL I see _hasp_logout@4

dumpbin showed the following:

 47   16 002C9E06 HL_LOGOUT

 14   41 0019056F hasp_logout

 

0 Kudos
Highlighted
New Contributor I
13 Views

I tried the !DEC$ statement again.

		function hasp_logout(handle) result(retval) bind(C, name="hasp_logout")
!DEC$ ATTRIBUTES STDCALL :: hasp_logout
			import
			integer(c_int32_t) :: handle
			integer :: retval
		end function

and this generated a compile error

...\CheckSentinelKey.f90(14): error #8143: The BIND(C) attribute for this symbol conflicts with a DEC$ ATTRIBUTES ALIAS, DECORATE, STDCALL, C, [NO_]MIXED_STR_LEN_ARG or REFERENCE attribute for this symbol.   [HASP_LOGOUT]

 

0 Kudos
Highlighted
Valued Contributor III
13 Views

What compiler version is that, is it an old one? The code below compiles OK with no errors. I am recalling a bug in an older version with use of RESULT, BIND Name= and STDCALL if my memory is good. Try it without using result. 

module test
    use, intrinsic :: iso_c_binding 
    implicit none 
    interface
        function hasp_logout(handle) result(retval) bind(C, name="hasp_logout")
            !DEC$ ATTRIBUTES STDCALL :: hasp_logout
            import
            integer(c_int32_t) :: handle
            integer :: retval
        end function
    end interface
end module test

 

0 Kudos
Highlighted
13 Views

>>integer(c_int32_t) :: handle
While your program is currently 32-bit, in the future you or your successor may port to 64-bit. Therefore, consider future-proofing your program by using

integer(int_ptr_kind()) :: handle

Jim Dempsey

0 Kudos
Highlighted
New Contributor I
13 Views

My compiler version is Intel(R) Visual Fortran Composer XE 2013 Update 5 Integration for Microsoft Visual Studio* 2010, 13.0.3636.2010,

The following still generates compile error 8143

module sentinel_api_mod 
	use, intrinsic :: iso_c_binding 
	implicit none 
	interface
		function hasp_logout(handle) bind(C, name="hasp_logout")
!DEC$ ATTRIBUTES STDCALL :: hasp_logout
			import
			integer(c_int32_t) :: handle
			integer :: hasp_logout
		end function
		
	END interface
end module sentinel_api_mod 

If remove the !DEC$ statement, compiling succeeds but linking fails with errors in post #4.

0 Kudos
Highlighted
Black Belt
13 Views

The bind(C... clause and the DEC$ directives are in conflict. Try removing the bind(C... part from the fifth line of the code in #9 .

0 Kudos
Highlighted
Black Belt Retired Employee
13 Views

In that old version, you could not use BIND(C) and STDCALL together. That changed in a later version. If you must use that version, you can't use BIND(C) if you need STDCALL and will have to use directives for everything.

0 Kudos
Highlighted
New Contributor I
13 Views

The Intel Software Manager tells me "you currently have the latest", but of course I don't.  When I try to login at signin.intel.com it won't let me login with credentials I know were good in 2017 and 2018.  I was able to login with older credentials from 2013, but that doesn't get me access to my current license.

In my Downloads folder I see I have downloaded the following files:

parallel_studio_xe_2018_update2_composer_edition_setup.exe

parallel_studio_xe_2017_update2_composer_edition_setup.exe

Can I install either of these without breaking anything?  Composer XE 2013 was bought and installed on one Serial number, and I have been using it with visual studio 2010 ever since.  In 2017 a new license for Intel Fortran,C++ and IMSL was purchased with a new serial number.  I never installed it out of fear of breaking my current setup because I read somewhere it was not compatible with visual studio 2010.

0 Kudos
Highlighted
New Contributor II
13 Views

Brian Murphy wrote:

The Intel Software Manager tells me "you currently have the latest", but of course I don't.  When I try to login at signin.intel.com it won't let me login with credentials I know were good in 2017 and 2018.  I was able to login with older credentials from 2013, but that doesn't get me access to my current license.

In my Downloads folder I see I have downloaded the following files:

parallel_studio_xe_2018_update2_composer_edition_setup.exe

parallel_studio_xe_2017_update2_composer_edition_setup.exe

Can I install either of these without breaking anything?  Composer XE 2013 was bought and installed on one Serial number, and I have been using it with visual studio 2010 ever since.  In 2017 a new license for Intel Fortran,C++ and IMSL was purchased with a new serial number.  I never installed it out of fear of breaking my current setup because I read somewhere it was not compatible with visual studio 2010.

 

Brian:

You need help from inside Intel. Devorah is the person who usually solves this type of problem for me in terms of access.  I strongly suggest you send her a private message - click on the icon next to your name on top right and you can see the private. 

She is excellent at sorting these types of access problems.  

John

0 Kudos
Highlighted
New Contributor I
13 Views

Steve, my intel product registration is hopelessly messed up.  I need to talk to someone over the phone to fix it.  Do you know of a phone number?

0 Kudos
Highlighted
New Contributor I
13 Views

I think I found the private message area by clicking near my name in the upper right, but could not figure out how to submit a message.  The name Devorah rings a distant bell.

0 Kudos
Highlighted
Black Belt Retired Employee
13 Views

You won't be able to start a private message thread - only Intel people and Black Belts can do that. There is no phone number available.

All licensing issues are supposed to be reported through the Online Service Center.

0 Kudos
Highlighted
New Contributor I
13 Views

I sent a distress call to inteldeveloperzonesupport@intel.com.  Hopefully they can clean up the mess with my registrations.

0 Kudos
Highlighted
Black Belt Retired Employee
13 Views

That may take a while to route properly - that team does not deal with product or licensing issues, they're strictly for issues with the IDZ web site. They may try to find the right team to handle it, but it depends a lot on who sees the message.

0 Kudos
Highlighted
New Contributor I
13 Views

I think I managed to submit the same thing at the intel Online Service Center.  I'll keep my fingers crossed.

Can you tell me if 

parallel_studio_xe_2018_update2_composer_edition_setup.exe 

is compatible with visual studio 2010?

Meanwhile, I took out the BIND(C stuff and the program now compiles and links.  Yippee!  So on to my next hurdle which is hasp_login that requires passing a string argument.  Yuck!  I will start another thread for that.

0 Kudos
Highlighted
Valued Contributor III
13 Views

Brian Murphy wrote:
Can you tell me if 

parallel_studio_xe_2018_update2_composer_edition_setup.exe 

is compatible with visual studio 2010?

https://software.intel.com/en-us/articles/intel-visual-fortran-compiler-180-for-windows-release-note...

 

 

0 Kudos