简体   繁体   English

MinGW / G ++ / g95链接错误-libf95未定义对“ MAIN_”的引用

[英]MinGW/G++/g95 link error - libf95 undefined reference to `MAIN_'

Summing up, my problem consists on compiling g95 objects inside a C++ application. 总结起来,我的问题在于在C ++应用程序内部编译g95对象。 Actually, I'm constructing an interface for an old fortran program. 实际上,我正在为旧的fortran程序构造一个接口。 For this task, I'm using the wxWidgets GUI library, and calling fortran subroutines when necessary. 对于此任务,我使用wxWidgets GUI库,并在必要时调用fortran子例程。 At the beginning, I was developing the entire project compiling my fortran files with gfortran (which comes with GCC) and linking them with my app by the g++ -o... command. 一开始,我正在开发整个项目,该项目使用gfortran(GCC随附)编译我的fortran文件,并通过g ++ -o ...命令将其与我的应用程序链接。 Everything was working fine but some numbers values calculated by my fotran subroutines returned NAN values. 一切工作正常,但是我的fotran子例程计算出的一些数值返回了NAN值。 Doing some research, I realized that compiling my fortran files with gfortran with the -m32 flag, generates this NAN values problem. 经过研究,我意识到使用带有-m32标志的gfortran编译我的fortran文件会产生此NAN值问题。 Although compiling with -m64 flag, my code works properly well. 尽管使用-m64标志进行编译,但我的代码可以正常运行。 The only trouble here is that my App should be 32bits and then I tryed another compiller. 唯一的麻烦是我的应用程序应该是32位,然后尝试了另一个编译器。 Here I found g95 Fortran compiler, which compiles my fortran code and gives the right output on a 32bits environment. 在这里,我找到了g95 Fortran编译器,该编译器编译了我的fortran代码并在32位环境中提供了正确的输出。 But when I'm trying to link these g95 objects into my program I see this following error: 但是,当我尝试将这些g95对象链接到程序中时,出现以下错误:

g++ -oCyclonTechTower.exe src\fortran\Modulo_Global.o src\fortran\Prop_Fisicas.o src\fortran\inversa.o src\fortran\tower.o src\fortran\PredadeCarga.o src\fortran\gota.o src\fortran\tadi.o src\view\SimulationORSATCustomDialog.o src\view\SimulationChildGUIFrame.o src\view\ParentGUIFrame.o src\view\ClientGUIFrame.o src\model\TowerData.o src\controller\SimulationController.o src\THEIACyclonTechTower.o ..\Resource\resource.o -Lc:\wxWidgets-2.6.4\lib -Lc:\MinGW\lib\gcc-lib\i686-pc-mingw32\4.1.2 -Bdynamic -Wl,--subsystem,windows -mwindows c:\wxWidgets-2.6.4\lib\libwx_mswu-2.6.a -lwxregexu-2.6 -lwxexpat-2.6 -lwxtiff-2.6 -lwxjpeg-2.6 -lwxpng-2.6 -lwxzlib-2.6 -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -lgcc -lf95
**c:\MinGW\lib\gcc-lib\i686-pc-mingw32\4.1.2/libf95.a(main.o):(.text+0x32): undefined reference to `MAIN_'
collect2: ld returned 1 exit status**
Build error occurred, build is stopped
Time consumed: 1531  ms. 

I have already read the g95 Manual for integration with C++ and I'm actually calling these functions bellow for controlling the fortran environment: void g95_runtime_start(int argc, char *argv[]); 我已经阅读了g95与C ++集成的手册,实际上是在调用以下函数来控制fortran环境:voi​​d g95_runtime_start(int argc,char * argv []); void g95_runtime_stop(); 无效的g95_runtime_stop();

I also included the g95 Fortran Runtime Library libf95.a and the libgcc.a into my linker command. 我还将g95 Fortran运行时库libf95.a和libgcc.a包含在我的链接器命令中。 Finishing, I don't have a main method implemented because this is managed by wxWidgets, and my fortran subroutines can not have a main function because this is a C++ program calling fortran functions. 最后,我没有实现main方法,因为它是由wxWidgets管理的,而我的fortran子例程不能具有main函数,因为这是一个调用fortran函数的C ++程序。

Can some of you guys help me with this problem? 你们中的一些人可以帮助我解决这个问题吗? How can I fix this undefined reference to MAIN__ problem? 如何解决对MAIN__问题的未定义引用? Any idea will be much appreciated. 任何想法将不胜感激。

I'm answering my own question because I got the solution. 我正在回答自己的问题,因为我找到了解决方案。 The problem wasn't with my g95 intergration. 问题不是我的g95集成。 I just overwrite the wxWidgets main macro for an int main function initialization as presented bellow: 我只是覆盖了wxWidgets main宏,以进行以下所示的int主函数初始化:

// Give wxWidgets the means to create a MyApp object
//IMPLEMENT_APP(MyApp);

int main(int argc, char *argv[]) {

    //MyWxApp derives from wxApp
    MyApp *myapp = new MyApp();
    wxApp::SetInstance( myapp );
    wxEntryStart( argc, argv );
    myapp->OnInit();

    myapp->OnRun();
    myapp->OnExit();
    wxEntryCleanup();

}

By the way, the required main function is now defined and my app is now working properly well without NAN values. 顺便说一句,现在已经定义了所需的主要功能,并且我的应用程序现在可以正常运行且没有NAN值了。

I hope that this question can help others. 我希望这个问题可以帮助其他人。

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

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