Gfortran 和 glut 实用程序:为什么我不能将它们链接到我的可执行文件中?



我试图让opengl在windows (XP 64位)下工作。我想把FORTRAN程序与opengl的"glut"实用程序链接起来。我正在运行这个批处理文件脚本:

REM default folder
@set MY_DIR= K:E_driveMy_openGL
REM where the F03G binding is located
@set BINDING_DIR= %My_DIR%fortran_binding
REM names of the F03G object files
@set MODULES= %BINDING_DIR%/glut_fonts.o  ^
     %BINDING_DIR%opengl_kinds.o  ^
     %BINDING_DIR%opengl_freeglut.o  ^
     %BINDING_DIR%opengl_glu.o  ^
     %BINDING_DIR%opengl_gl.o
REM the compile flags
@set FFLAGS= -Wall -Wextra -pedantic -fcheck=all ^
         -fcheck=do -fwhole-file -funroll-loops -ftree-vectorize ^
         -Wsurprising -Wconversion -Wconversion-extra -static ^
         -I%BINDING_DIR%
@set FFOLDER= C:Compilersmingw-w64i686-4.9.0-posix-dwarf-rt_v3-rev2mingw32bin
%FFOLDER%gfortran %FFLAGS%   -c  RandomSphere_FreeGLUT.f90
%FFOLDER%gfortran %FFLAGS%  RandomSphere_FreeGLUT.o -static %MODULES%   -o randomsphere_freeglut_main

该脚本运行正常,直到并包括编译命令(上面最后第二个命令)。然而,link命令(上面最后一个)会创建这些错误消息:

RandomSphere_FreeGLUT.o:RandomSphere_FreeGLUT.f90:(.text+0x3e): undefined reference to `glutInitDisplayMode'
RandomSphere_FreeGLUT.o:RandomSphere_FreeGLUT.f90:(.text+0x4a): undefined reference to `glutCreateWindow'
RandomSphere_FreeGLUT.o:RandomSphere_FreeGLUT.f90:(.text+0x58): undefined reference to `glutSetWindowData'
RandomSphere_FreeGLUT.o:RandomSphere_FreeGLUT.f90:(.text+0x64): undefined reference to `glGenLists'
(... 24 more similar messages about "undefined reference to" something starting with "gl" ...)
C:/Compilers/mingw-w64/i686-4.9.0-posix-dwarf-rt_v3-rev2/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.0/../../../../i686-w64-mingw32/bin/ld.exe: RandomSphere_FreeGLUT.o: bad reloc address 0x20 in section `.eh_frame'
collect2.exe: error: ld returned 1 exit status

我的解释是链接器找不到过剩的实用程序(当然我可能错了!)。我确实有dll"glut32.dll"one_answers"FGlut32.dll",但我无法将它们的存在传达给链接器(gfortran)。我尝试了很多方法让fortran找到它们,但都失败了。我如何让gfortran找到这些过剩的实用程序并将它们编译到我的可执行文件中?这是怎么回事?

使用-L和-L的组合,对于您的-L/directory/where/glut/library/exists-lglut32 (-lFGlut32)

您使用mingw链接器,因此可以在官方页面上找到其他信息

相关内容

最新更新