C++ cli 从C+调用Fortran+-CLI 我有一个FORTRAN子程序,fortrSAMP,和一个C++主函数,HandShakingTest.cpp。 我试图从CLR C++调用FORTRAN子程序。
我收到两批错误。让我们称之为错误(1)和错误(2)。如果您能帮助我理解这些错误发生的原因,我将不胜感激 当我尝试使用以下内容进行编译时: cl/clr握手测试.cpp 我得到以下错误(1): 错误(2)包括:C++ cli 从C+调用Fortran+-CLI 我有一个FORTRAN子程序,fortrSAMP,和一个C++主函数,HandShakingTest.cpp。 我试图从CLR C++调用FORTRAN子程序。,c++-cli,fortran,linker-errors,handshaking,C++ Cli,Fortran,Linker Errors,Handshaking,我收到两批错误。让我们称之为错误(1)和错误(2)。如果您能帮助我理解这些错误发生的原因,我将不胜感激 当我尝试使用以下内容进行编译时: cl/clr握手测试.cpp 我得到以下错误(1): 错误(2)包括: MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(cla ss type_info const &)" (??0type_info@@AAE@ABV0@@Z) alr
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(cla
ss type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typin
fo.obj)
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_i
nfo::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defin
ed in LIBCMT.lib(typinfo.obj)
MSVCRT.lib(merr.obj) : error LNK2005: __matherr already defined in LIBCMT.lib(_matherr
_.obj)
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NOD
EFAULTLIB:library
HandShakingTest.obj : error LNK2028: unresolved token (0A00030A) "extern "C" void __cd
ecl FortranShake(int &)" (?FortranShake@@$$J0YAXAAH@Z) referenced in function "int __c
lrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@Syst
em@@@Z)
HandShakingTest.obj : error LNK2019: unresolved external symbol "extern "C" void __cde
cl FortranShake(int &)" (?FortranShake@@$$J0YAXAAH@Z) referenced in function "int __cl
rcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@Syste
m@@@Z)
libifcoremt.lib(for_main.obj) : error LNK2019: unresolved external symbol _MAIN__ refe
renced in function _main
test.exe : fatal error LNK1120: 3 unresolved externals
您的第一个错误实际上是链接器错误-如果没有
/c
命令行开关,您只需一步编译和链接。没有提供Fortran代码或目标代码
您的第二个错误是因为:
/MD
添加到ifort命令行,该命令行指定动态链接
<> LI> 如果没有编译器选项或指令,相反,FORTRAN编译器生成的C代码中FORTRAN过程的等效标识符是FORTRAN过程名称的大写变体——即在C++代码调用过程fortrStray.如果您可以按照F2003标准编写Fortran代码,则应使用该语言的C互操作性功能(
BIND(C,…)
)来控制Fortran过程的C绑定名称,并确保调用约定等保持一致
<> L> >P> Fortran子程序的哑参数具有双精度类型说明符,在C++编译器中,这与编译器的组合相当,而不是<代码> int >代码>。同样,F2003引入的特性可以使参数类型的对齐更加健壮
- 您的第一个错误实际上是链接器错误-如果没有
/c
命令行开关,您只需一步编译和链接。没有提供Fortran代码或目标代码
您的第二个错误是因为:
/MD
添加到ifort命令行,该命令行指定动态链接
<> LI> 如果没有编译器选项或指令,相反,FORTRAN编译器生成的C代码中FORTRAN过程的等效标识符是FORTRAN过程名称的大写变体——即在C++代码调用过程fortrStray.如果您可以按照F2003标准编写Fortran代码,则应使用该语言的C互操作性功能(
BIND(C,…)
)来控制Fortran过程的C绑定名称,并确保调用约定等保持一致
<> L> >P> Fortran子程序的哑参数具有双精度类型说明符,在C++编译器中,这与编译器的组合相当,而不是<代码> int >代码>。同样,F2003引入的特性可以使参数类型的对齐更加健壮
ifort /c FortranShake.f //Which compiles fine
cl /c /clr HandShakingTest.cpp //compiles fine
cl /o test HandShakingTest.obj FortranShake.obj //ERROR(2) occurs
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(cla
ss type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typin
fo.obj)
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_i
nfo::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defin
ed in LIBCMT.lib(typinfo.obj)
MSVCRT.lib(merr.obj) : error LNK2005: __matherr already defined in LIBCMT.lib(_matherr
_.obj)
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NOD
EFAULTLIB:library
HandShakingTest.obj : error LNK2028: unresolved token (0A00030A) "extern "C" void __cd
ecl FortranShake(int &)" (?FortranShake@@$$J0YAXAAH@Z) referenced in function "int __c
lrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@Syst
em@@@Z)
HandShakingTest.obj : error LNK2019: unresolved external symbol "extern "C" void __cde
cl FortranShake(int &)" (?FortranShake@@$$J0YAXAAH@Z) referenced in function "int __cl
rcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@Syste
m@@@Z)
libifcoremt.lib(for_main.obj) : error LNK2019: unresolved external symbol _MAIN__ refe
renced in function _main
test.exe : fatal error LNK1120: 3 unresolved externals
#include "stdio.h"
#include <stdlib.h>
#include <Windows.h>
#using <System.DLL>
#using <System.Windows.Forms.DLL>
using namespace std;
using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
extern "C" {void FortranShake(int&);}
int main(array<System::String ^> ^args)
{
Process^ testHand = gcnew Process();
testHand->StartInfo->UseShellExecute = false;
testHand->StartInfo->RedirectStandardInput = true;
testHand->StartInfo->RedirectStandardOutput = true;
testHand->StartInfo->ErrorDialog = true;
int numDebug = 0;
String^ returnedDebug = "Nothing";
FortranShake(numDebug);
StreamReader^ FromHandProcess = testHand->StandardOutput;
StreamWriter^ ToHandProcess = testHand->StandardInput;
String^ Line;
Line = FromHandProcess ->ReadLine();
if (Line->Equals("Enter Hand") )
{
Console::WriteLine(L"Hand Started!");
}
ToHandProcess ->WriteLine(numDebug.ToString());
returnedDebug = FromHandProcess ->ReadLine();
MessageBox::Show(returnedDebug);
return 0;
}
SUBROUTINE FortranShake(GP_DEBUG)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
INN = 5
WRITE(06,'(a)') 'Enter Hand'
READ(INN,*) GP_DEBUG
GP_DEBUG = GP_DEBUG + 55
WRITE(06,*) GP_DEBUG
RETURN
END