开发者

Linking mixed FORTRAN and C++ in the Visual studio 2008 environment

开发者 https://www.devze.com 2023-04-01 07:15 出处:网络
I am calling a C++ function from FORTAN using ISO_C_Binding module. I can compile and link the Fortran and C++ files using MINGW g++ and g开发者_开发知识库fortran command line option using the command

I am calling a C++ function from FORTAN using ISO_C_Binding module. I can compile and link the Fortran and C++ files using MINGW g++ and g开发者_开发知识库fortran command line option using the command sequence

gfortran -c main.f90

g++ -c print_hi.cpp

for compiling and for linking I can use the gfortran option and including the C++ standard libraries as

gfortran main.o print_hi.o -o main -lstdc++

which work absolutely fine. Now my questions is how can I do the same in the visual studio environment. In case of simple C we will just include the print_hi.o file in the additional dependencies in the linker but if I only include this C++ file (print_hi.o), it gives errors like

 Error LNK2010: unresolved external symbol _ZSt4cout referenced in function _print_hi

So I guess I need to give the path to the C++ libraries in my FORTRAN project as we are doing in the command line MINGW case but I don’t know how to do this.

PS: I am using windows Vista, with intell visual fortran compiler professional edition 11.1 in Visual studio 2008 and C++ in Visual studio 2010 in the same computer.


This MSDN articles can help you: Mixed-Language Issues and Mixed-Language Programming with C++

Only pay attention that all this concerns VC++ 6.0.


Go to Project Properties -> Linker -> Input -> Additional Dependencies, and enter the library names there.


Make sure you statically build with the gfortran run-time library Try gfortran -static-libgfortran (-c or -S) -f2003 yourfortransource.f90 . You should get an object file with an .o extension.

Then bring the object file over to your MS compiler. Compile your C/C++ source code to an object file only. Last do a normal build with the two object files together. Do this with the command line compiler to make sure it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号