i am writing a program in Fortran which uses .mod files, .dll libraries and .h headers.
I must be forgetting something when i call the compiler, because i get the error: undefined reference to '__[module_name]_MOD_[function_name]', where [module_name] is the name of one of the modules used by the main program and [function_name] is the name of a function contained in the module.
The only source file is called 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
The function final_orbit called by the subroutine CON is contained in the module "problem_definition_tools".
For the compilation i use the following windows batch file called "compile.bat"
x86_64-w64-mingw32-gfortran src\MAIN.f90 -cpp -Iinclude -Ifinclude\worhp -Ifinclude\aerospace -Jobj -Lbin -lworhp -o bin\megaceppa.exe
which gives the error
undefined reference to '__problem_definition_tools_MOD_final_orbit'
I run the command from the directory 'Test' which has the following structure
- \bin\
- libworhp.dll
- \finclude
- \worhp\
- std.mod
- \aerospace\
- problem_definition_tools.mod
- \worhp\
- \include
- \worhp\
- macros.h
- \worhp\
- \lib
- libworhp.lib
- \obj
- worhp_interface.mod
- \src
- MAIN.f90
- compile.bat
I would like to specify that the module "problem_definition_tools" is written by me, and i know for sure that it works because i already used it in another program. Moreover, i re-compiled it with x86_64-w64-mingw32-gfortran in order to avoid any compatibility issues with this program.
I am sure that there is something wrong in the way i call the compiler, but i can't figure it out because of my limited experience with Fortran. I also triend to search for similar questions on this website, but i couldn't find anything closely related to my problem.
.modfile is produced. But not impossible. An object file/library needn't always be required when a module isused. So, could you show the compilation of the module? Although it isn't my system or compiler of choice so I may not be much more help.problem_definition_tools.f90in the compilation, now everything compiles flawlessly. Strangely enough, even this compilation doesn't produce any.oor.objfile, but i don't care as long as it works! Thanks for the help!