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.

Call C++ dll from Fortran

markusda
Beginner
4,749 Views

Hello,

This is my first post in this forum and I'm pretty new at this visual studio stuff, if this is the wrong forum let me know which one it should be in.

I am a FORTRAN user who has a need to make calls and extract data from a C++ routine. I am not familiar with C++, nor am I very familiar with mixed language programming in general. The biggest stumbling block I have is trying to get the two codes to "see" and "like" each other if you will.

Here is what I'm using:

Intel Fortran 12 Compiler

Microsoft Visual Studio2008

I'm going to start out with baby steps first. Below is a Hello World C++ program

[bash]// test.h #define CALL __declspec(dllexport) namespace testfuncs{ class testfuncs extern "C" void CALL cwrite_ (); } // testfuncs.cpp #include "test.h" #include #include using namespace std; namespace testfuncs { extern "C" void CALL cwrite_ (); }[/bash]

This seems to build okay and it creates a DLL named Cdll.dll.

First Problem ... There is no *.lib

I simply want to call this from a simple FORTRAN routine such as

program Forcall
implicit none
call write
end program Forcall

Any ideas?

0 Kudos
24 Replies
ye_T_1
Beginner
702 Views

Hi

By following the steps. I've always been successful to compile the cpp dll while when it comes to fortran main program, it keeps on telling me "error LNK2019: unresolved external symbol berechnung referenced in function MAIN__". Am I wrong in terms of linker setup? What should I do?

0 Kudos
Steven_L_Intel1
Employee
702 Views

If you are using VS2012 (or maybe also VS2010), C DLL projects that are dependents of Fortran projects don't automatically get linked in.  This is a Microsoft bug. The workaround is to add the DLL project's export library to the Fortran project directly.

0 Kudos
ye_T_1
Beginner
702 Views

Hi Steve

Thank you very much for your help. I works now. I wonder do you know any tutorial talking about call a java dll from fortran main program? Thanks

Steve Lionel (Intel) wrote:

If you are using VS2012 (or maybe also VS2010), C DLL projects that are dependents of Fortran projects don't automatically get linked in.  This is a Microsoft bug. The workaround is to add the DLL project's export library to the Fortran project directly.

0 Kudos
Steven_L_Intel1
Employee
702 Views

I don't, but I would expect a DLL to be a DLL, really. All you should have to worry about is getting the routine name, calling convention and arguments correct. However, I'd also expect a Java DLL to not provide an export library, which means you probably have to use the LoadLibrary and GetProcAddress Windows API routines.  We provide a DLL\DynamicLoad sample illustrating this.

0 Kudos
Reply