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

Linking problem

Clive_J_1
Beginner
824 Views

I have a piece of code to call the C function GetAdaptersInfo to obtain the MAC address(es) of the computer.

The (abridged) code that works is

USE IFWINTY

! define Fortran equivalents of required C structures

INTERFACE
  INTEGER (BOOL) FUNCTION GetAdaptersInfo(arg1, arg2)   !                       &
 !&                                              BIND(C, NAME='GetAdaptersInfo')
!DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'GetAdaptersInfo' :: GetAdaptersInfo
  USE IFWINTY
  INTEGER (LPLONG) :: arg1
  INTEGER (LPLONG) :: arg2
  END FUNCTION GetAdaptersInfo
END INTERFACE

dwRetVal = SIZEOF(AdapterInfo)

iret = GetAdaptersInfo(LOC(AdapterInfo), LOC(dwRetVal))

However, I would prefer to do it the ISO standard way instead of using specific compiler directives so if I have tried changing the code to

USE IFWINTY
USE ISO_C_BINDING

INTERFACE
  INTEGER (BOOL) FUNCTION GetAdaptersInfo(arg1, arg2)                          &
  &                                              BIND(C, NAME='GetAdaptersInfo')
  USE IFWINTY
  USE ISO_C_BINDING
  INTEGER (LPLONG) :: arg1
  INTEGER (LPLONG) :: arg2
  END FUNCTION GetAdaptersInfo
END INTERFACE

but then it fails in the linker step cannot resolve _GetAdaptersInfo

What am I doing wrong.

TIA

Clive

0 Kudos
3 Replies
IanH
Honored Contributor III
824 Views

Are you compiling for 32 bit windows?  If so, the Windows API calls are not "C compatible" and you therefore cannot use BIND(C). 

(Hence the use of the STDCALL directive in your original code.)

0 Kudos
Clive_J_1
Beginner
824 Views

Yes it is 32bit windows. Guess I will have to stick with the compiler directives.

0 Kudos
Clive_J_1
Beginner
824 Views

First of all I apologise for seemingly creating two threads of the same post.

I have done some more research and the problem has been raised before and it is down to the STDCALL directive. Apparently, it is a restriction of Intel Fortran that such procedures may not be linked with BIND(C) so I am stuck with using the compiler directive.

0 Kudos
Reply