Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Linking problem

Clive_J_1
Beginner
790 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
2 Replies
mecej4
Honored Contributor III
790 Views

If you are targeting IA32, one of the WIndows system libraries will provide the routine _GetAdaptersInfo@8, and that routine has to be called using the Stdcall convention. You provided an interface that does not correspond to any routine provided in the Windows SDKs, so you get a link-time error.

The name decoration and calling conventions for X64 are different from those for IA32, and you will need to adjust your code accordingly, if that is the platform that you wish to compile for.

0 Kudos
Bernard
Valued Contributor I
790 Views

As it was already said your code must use stdcall convention when calling Win32 API.

0 Kudos
Reply