简体   繁体   English

调用C ++函数的Fortran程序编译错误

[英]Compile error with Fortran program calling c++ function

I'm trying to link a C++ function at compile time into a Fortran program. 我正在尝试在编译时将C ++函数链接到Fortran程序中。 I'm compiling with mpif90 using a make file. 我正在使用make文件使用mpif90进行编译。 I add the C++ object file to object files list within the latter. 我将C ++目标文件添加到后者中的目标文件列表中。 The function compiles fine on its own via 该函数可以通过自己很好地编译

g++ -c -o quenchf.o quenchf.cpp g ++ -c -o淬火.o淬火.cpp

but when I add the .o file to the make file for my Fortran program file I get the error: 但是,当我将.o文件添加到Fortran程序文件的make文件中时,出现错误:

quenchf.o: In function Optim::Optim(double, double, int, int)': quenchf.cpp:(.text+0x1348): undefined reference to operator new[](unsigned long)' quenchf.cpp:(.text+0x1359): undefined reference to operator new[](unsigned long)' quenchf.cpp:(.text+0x136d): undefined reference to operator new[](unsigned long)' quenchf.cpp:(.text+0x1381): undefined reference to operator new[](unsigned long)' quenchf.cpp:(.text+0x1395): undefined reference to operator new[](unsigned long)' quenchf.o:quenchf.cpp:(.text+0x13a9): more undefined references to operator new[](unsigned long)' follow quenchf.o:(.eh_frame+0x13): undefined reference to __gxx_personality_v0' make: * [ljnpt.exe] Error 1 tinyf.o:在函数Optim::Optim(double, double, int, int)': quenchf.cpp:(.text+0x1348): undefined reference to运算符new [](unsigned long)'的引用淬灭.cpp :(。 text + 0x1359):未定义对operator new[](unsigned long)' quenchf.cpp:(.text+0x136d): undefined reference to运算符new [](无符号长)的引用淬火.cpp :(。text + 0x1381) :未定义引用operator new[](unsigned long)' quenchf.cpp:(.text+0x1395): undefined reference to运算符new [](unsigned long)'淬火.o:quenchf.cpp :(。text + 0x13a9) :对operator new[](unsigned long)' follow quenchf.o:(.eh_frame+0x13): undefined reference to更多未定义引用,请operator new[](unsigned long)' follow quenchf.o:(.eh_frame+0x13): undefined reference to __gxx_personality_v0'的operator new[](unsigned long)' follow quenchf.o:(.eh_frame+0x13): undefined reference to使: * [ljnpt.exe]错误1

Do I need to link in a C++ to Fortran library? 我是否需要在C ++中链接到Fortran库? I instantiate a C++ object in the c function so perhaps this is causing a problem. 我在c函数中实例化了一个C ++对象,所以也许这引起了问题。

Thanks for any help- 谢谢你的帮助-

You have not linked to the C++ runtime (which provides stuff like operator new[](unsigned long) ). 您尚未链接到C ++运行时(它提供了类似operator new[](unsigned long) )。 Trouble is, you'll need both the C++ and the Fortran runtime, and I'm not sure how to accomplish that, but there must be a way with the linker flags. 麻烦的是,您将同时需要C ++和Fortran运行时,但我不确定如何实现此目标,但是必须有一种使用链接器标志的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM