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

Mixed C++ and Fortran programming problem.

Shaun_B_
初學者
945 檢視

Hi, I am working on a project with C++, and there is a old ordinary equation integrator named lsode written in fortran, I'd like to call its subrutine in C++. 

I  followed the instruction on this link to Configue Microsoft Visual Studio 2010.(vv=12 for me.)

http://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications

And then creat a solution with one C++ project and one fortran static library projbec, as in:

http://software.intel.com/en-us/articles/intel-fortran-compiler-for-windows-building-mixed-language-applications-under-visual-studio/

Set the dependency and start up project. Also explicitly provide the path to the Fortran library, in the C/C++ project's Linker > Additional Dependencies property, or as a "source file" in the project, like Steve said!

I test a "hello world! " program written in fortran and called in C++, it works perfectly!

But when I follow the procedure above and incorporate the old fortran code(a simple test), I got the error:

1>lsode_init.obj : error LNK2001: unresolved external symbol _ckstrt_
1>main.obj : error LNK2019: unresolved external symbol _chemkininitialize_ referenced in function _main

Below is my source codes:

I upload every source file, global_extern_vars.h contains the extern "C" stuff, use_chemkin.f is a wrapper to the old fortran codes.

Hope someone could help me.(I have worked on this problem for one week, my boss got unhappy with me as He bought VS2010 and intel fortran complier but I don't know how to use...). It would be really appreciated if u could help to fix it.

 

0 積分
4 回應
Steven_L_Intel1
945 檢視

Your program was written assuming common defaults for Fortran on Linux. The C++ code assumes that Fortran routine names are downcased and have an underscore at the end, neither of which are the defaults of Intel Visual Fortran.

Perhaps the easiest solution is to change the names of the Fortran entities in the C++ code to have uppercase names and remove the trailing underscore. Another option is to add BIND(C) attributes where appropriate, with a NAME= value that is the lowercase name with the underscore at the end. I see you have a COMMON block, so that's slightly trickier (need a BIND statement), but doable.

SergeyKostrov
傑出貢獻者 II
945 檢視
Could you try to change the following in global-extern-vars.h from: ... extern "C" { ... // your declarations... ... } to: ... #ifdef __cplusplus extern "C" { #endif ... // your declarations... ... #ifdef __cplusplus } #endif
SergeyKostrov
傑出貢獻者 II
945 檢視
This is because your main C/C++ source file ( lsode-init.cpp ) has extension cpp.
Shaun_B_
初學者
945 檢視

Thanks a million!!! I try all your solutions and Steve's idea works better! I simply migrate linux codes to windows which is not correct!

回覆