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

C++ main cannot load Fortran DLL that has ALLOCATE statements

Sungmin31
Novice
699 Views

I have just installed the latest HPC toolkit (intel-oneapi-hpc-toolkit-2025.0.1.48_offline.exe). 

C++ main and a Fortran project are shown below.

Test.cpp

#include <iostream>
#include <Windows.h>
int main()
{
    HINSTANCE hDLL = LoadLibrary(L"FPROJ.dll");
    if (hDLL == NULL)
        std::cout << "DLL loading FAIL!" << std::endl;
    else
        std::cout << "DLL loading SUCCESS!" << std::endl;
}

FPROJ.for

      INTEGER*4 FUNCTION MYPROJ(N)

      !MS$ ATTRIBUTES DLLEXPORT::MYPROJ

      INTEGER*4,ALLOCATABLE::IARR(:)
      !ALLOCATE(IARR(2*N))     ! C++ cannot load this DLL if this line is uncommented.
     
      MYPROJ = 1

      RETURN
      END

The VS 2019 project is shown below.

Sungmin31_0-1740091989630.png

The FPROJ project creates a FPROJ.dll

  • With the FPROJ.for shown above that commented out the ALLOCATE statement, the C++ main loads the FPROJ.dll successfully.
  • However, if the ALLOCATE statement is uncommented, the FPROJ.dll cannot be loaded in run time.

I cannot figure out why having the ALLOCATE statement in the Fortran dll function causes the dll loading issue in C++.

Is this a known issue with the latest IFX compiler or does any one experience the same issue?

A complete set of project files is attached if any one wanted try my codes.

0 Kudos
1 Solution
Sungmin31
Novice
677 Views

Hi Steve,

You are right on. 

I guess the code without the ALLOCATE statements did not need oneapi libraries.

I added the oneAPI\2025.0\bin in the PATH variable then the code with the ALLOCATE statements works.

Thanks a lot.

View solution in original post

0 Kudos
3 Replies
Steve_Lionel
Honored Contributor III
690 Views

This usually means that a dependent DLL is not found by Windows. In your case it is almost certainly the Intel Fortran run-time support DLL.  My guess, especially if you are running this from inside VS, is that the Intel DLLs have not been added to PATH. Sometimes logging out and in again will fix this (you should need to do this only once.) 

0 Kudos
Sungmin31
Novice
688 Views

Hi Steve,

Thanks for the prompt response.

[A] The same project with just the ALLOCATE statement commented out works perfectly fine.

[B] If the ALLOCATE statement is uncommented, it does NOT work.

If my PATH or other settings are not correct, neither should work.  However, [A] works but not [B].

0 Kudos
Sungmin31
Novice
678 Views

Hi Steve,

You are right on. 

I guess the code without the ALLOCATE statements did not need oneapi libraries.

I added the oneAPI\2025.0\bin in the PATH variable then the code with the ALLOCATE statements works.

Thanks a lot.

0 Kudos
Reply