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

Create Single DLL with both Fortran and C++ exports

mattintelnetfort
Beginner
558 Views

I'm trying to create a single DLL with both Fortran and C++ libraries linked into it. I need to have subroutines and C++ classes and methods available to the consumers of the DLL.

I understand from the documentation and this newsgroup that you cannot have C++ and Fortran source files in the same project, but believe you can achieve my goal by putting C++ in one project and Fortran in another lib project, then linking them into a single DLL. I cannot find documentation to support, and have failed in attempting this myself. Can someone provide a sample and/or give me some guidance in this area? I'm using Intel Fortran 9.X and Visual Studio 2005.

Thanks!

0 Kudos
3 Replies
Steve_Nuchia
New Contributor I
558 Views

There is an example shipped with the compiler (at least since 10.0.something) that shows all combinations of X-calls-Y with static and DLL linkage. But is does not illustrate dllexport from a fortran .libproject through a C++ DLL project.

I haven't tried itbut it should just work. Can you provide an expanded discussion of "failed in attempting this"?

0 Kudos
mattintelnetfort
Beginner
558 Views

I have a attempted to add an additional C++ basedlibrary to a previously all Fortran DLL (a DLL with several Fortran based libraries/projects linked into a single DLL). The compile and link of the mixed DLL (let's call it A) seems to be OK, but when I try to link another DLL (let's call it B) which depends on A and has references to both Fortran and C++ symbols in A, the C++ symbols are unresolved and B fails to link.

Thanks for your help.

0 Kudos
Abhijit_Yelegaonkar_
558 Views

#include

"stdafx.h"

#include

"CPPDLL.h"

#include

#ifdef

_MANAGED

#pragma managed(push, off)

#endif

BOOL APIENTRY DllMain( HMODULE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

#ifdef

_MANAGED

#pragma managed(pop)

#endif

// The following function is exported:

extern

"C" { CPPDLL_API

double __stdcall ABC()

{

DEMO () ; //calling the fortran export

}

Note:-add the fortran lib file to the this solution.

Also,

In the properties of this solution->Linker->Input->Additional Dependencies->specify the fortran lib file.

Your fortran dll can be like this:-

Subroutine

DEMO()

!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"DEMO" :: DEMO

!body

End Subroutine

DEMO

0 Kudos
Reply