我正在Fortran中编写一个程序,它使用.mod文件,.dll库和.h标题。
当我调用编译器时,我必须忘记一些事情,因为我收到错误: 未定义引用'__ [module_name] _MOD_ [function_name]',其中[module_name]是主程序使用的模块之一的名称,[function_name]是模块中包含的函数的名称。
唯一的源文件名为MAIN.f90:
! WORHP workspace access macros
#include "worhp/macros.h"
MODULE WORHP_INTERFACE
USE std
USE problem_definition_tools
CONTAINS
SUBROUTINE OBJ(N,X,F) BIND(C)
INTEGER(WORHP_INT) :: N
REAL(WORHP_DOUBLE) :: X(N),F
INTENT(in) :: N, X
INTENT(out) :: F
F = X(1)
END SUBROUTINE OBJ
SUBROUTINE CON(N,M,X,G) BIND(C)
INTEGER(WORHP_INT) :: N,M
REAL(WORHP_DOUBLE) :: X(N),G(M)
INTENT(in) :: N, M, X
INTENT(out) :: G
TYPE (orbit) :: O
O = final_orbit(X)
G = [O%Lp, O%La]
END SUBROUTINE CON
SUBROUTINE DOBJ(N,dfnnz,DFROW,X,DF) BIND(C)
INTEGER(WORHP_INT) :: N,dfnnz,DFROW(DFnnz)
REAL(WORHP_DOUBLE) :: X(N),DF(DFnnz)
INTENT(in) :: N, DFnnz, DFrow, X
INTENT(out) :: DF
DF = [1, 0, 0, 0, 0, 0]
END SUBROUTINE DOBJ
SUBROUTINE DCON(N,M,DGnnz,DGROW,DGCOL,X,DG) BIND(C)
INTEGER(WORHP_INT) :: N,M,DGnnz,DGROW(DGnnz),DGCOL(DGnnz)
REAL(WORHP_DOUBLE) :: X(N),DG(DGnnz)
INTENT(in) :: N,M,DGnnz,DGrow,DGcol,X
INTENT(out) :: DG
! Dummy
END SUBROUTINE DCON
SUBROUTINE HESS(N,M,HMnnz,HMrow,HMcol,X,Mu,HM) BIND(C)
INTEGER(WORHP_INT) :: N, M, HMnnz, HMrow(HMnnz), HMcol(HMnnz)
REAL(WORHP_DOUBLE) :: X(N),Mu(M),HM(HMnnz)
INTENT(in) :: N, M, HMnnz, HMrow, HMcol, X, Mu
INTENT(out) :: HM
! Dummy
END SUBROUTINE HESS
END MODULE WORHP_INTERFACE
program MAIN
USE WORHP_INTERFACE
USE Worhp_User
INTEGER (WORHP_INT) :: Mode, N, M, DFnnz, DGnnz, HMnnz
PARAMETER (N=6, M=2, DFnnz=1, DGnnz=12, HMnnz=12)
INTEGER (WORHP_INT) :: DFrow(DFnnz), DGrow(DGnnz), DGcol(DGnnz)
INTEGER (WORHP_INT) :: HMrow(HMnnz), HMcol(HMnnz)
INTEGER (WORHP_INT) :: Iparam(10)
REAL (WORHP_DOUBLE) :: X(N), L(N+M), U(N+M), Dparam(10)
REAL (WORHP_DOUBLE) :: Infty = 1d20
! Check Version of library and header files
CHECK_WORHP_VERSION
L = [9000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 200000.0, 35786000.0]
U = [10000.0, 5.0, 180.0, 0.15, 180.0, 0.15, 200000.0, 35786000.0]
X = [9520.00, 1.47490136, 71.50755639, 0.09948622, 97.00248532, 0.09296147]
DFrow = [6]
DGrow = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
DGcol = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]
HMrow = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
HMcol = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]
! Get default parameter values
Mode = 0
CALL WorhpSimple(Mode, N, M, X, L, U, Dparam, Iparam, &
DFnnz, DFrow, DGnnz, DGrow, DGcol, HMnnz, HMrow, HMcol, &
OBJ, CON, DOBJ, DCON, HESS)
! User-defined derivatives are available
Iparam(1) = 1
Iparam(2) = 0
Iparam(3) = 0
! Run the solver
Mode = 1
CALL WorhpSimple(Mode, N, M, X, L, U, Dparam, Iparam, &
DFnnz, DFrow, DGnnz, DGrow, DGcol, HMnnz, HMrow, HMcol, &
OBJ, CON, DOBJ, DCON, HESS)
end
子程序final_orbit
调用的函数CON
包含在模块“problem_definition_tools”中。
对于编译,我使用以下名为“compile.bat”的Windows批处理文件
x86_64-w64-mingw32-gfortran src\MAIN.f90 -cpp -Iinclude -Ifinclude\worhp -Ifinclude\aerospace -Jobj -Lbin -lworhp -o bin\megaceppa.exe
给出错误
undefined reference to '__problem_definition_tools_MOD_final_orbit'
我从“Test”目录运行命令,该目录具有以下结构
我想指定模块“problem_definition_tools”是由我编写的,我确信它有效,因为我已经在另一个程序中使用过它。此外,我使用x86_64-w64-mingw32-gfortran重新编译它,以避免与此程序的任何兼容性问题。
我确信我调用编译器的方式有问题,但由于我对Fortran的经验有限,我无法理解。我也试图在这个网站上搜索类似的问题,但我找不到与我的问题密切相关的任何内容。
答案 0 :(得分:0)
我认为这可能与final_orbit
函数的某些声明有关。
似乎接近以下问题:
Linking fortran module: "undefined reference"
我认为问题应该放在模块problem_definition_tools