这是我的生成文件:
PROGRAM = mf2005-GPU.f
# Define the Fortran compile flags
F90FLAGS= -g -fopenmp
F90= gfortran
# Define the C compile flags
# -D_UF defines UNIX naming conventions for mixed language compilation.
CFLAGS= -D_UF -O3
CC= gcc
CPPFLAGS= -Dcpp_variable
CXX= g++
# Define GMG objects
#
GMG = r_vector.o\
solvers.o\
ccfd.o\
mf2kgmg.o\
# Define the libraries
SYSLIBS= -lc
USRLIB =
CUDA_LIB64=/cm/shared/apps/cuda40/toolkit/4.0.17/lib64/
LFLAGS = -L$(CUDA_LIB64) -lcuda -lcudart -lcusparse -lcublas -lpthread -lm -lcufft -lcurand -lnpp -lgomp
# Define all object files which make up MODFLOW
OBJECTS = \
dblas.o\
gwf2bas7.o \
de47.o \
dlapak.o\
pcg7.o \
sip7.o \
gmg7.o \
mhc7.o \
gwf2bcf7.o \
gwf2lpf7.o \
gwf2huf7.o \
gwf2rch7.o \
gwfuzfmodule.o \
gwfsfrmodule.o \
gwf2lak7.o \
gwf2sfr7.o \
gwf2uzf1.o \
gwf2gag7.o \
gwf2chd7.o \
gwf2drn7.o \
gwf2drt7.o \
gwf2ets7.o \
gwf2evt7.o \
gwf2fhb7.o \
gwf2ghb7.o \
gwf2hfb7.o \
gwf2ibs7.o \
gwf2res7.o \
gwf2riv7.o \
gwf2str7.o \
gwf2sub7.o \
gwf2swt7.o \
gwf2wel7.o \
hufutl7.o \
obs2bas7.o \
obs2drn7.o \
obs2ghb7.o \
obs2riv7.o \
obs2chd7.o \
obs2str7.o \
parutl7.o \
gwf2mnw17.o \
gwf2mnw27.o \
gwf2mnw2i7.o \
utl7.o \
lmt7.o \
gwf2hydmod7.o \
upcg7.o \
upcgc.o \
upcg7lanczos.o \
upcg7polya.o \
upcg7polyu.o \
mf2005-GPU.o \
# Define Task Function
all: mf2005-GPU
# Define what mf2005
mf2005-GPU: $(OBJECTS) $(GMG)
-$(F90) $(F90FLAGS) -o mf2005-GPU $(OBJECTS) cuda_kernels.o $(GMG) $(USRLIB) $(SYSLIBS) $(LFLAGS)
# Object codes
.f.o:
$(F90) $(F90FLAGS) -c $<
.c.o:
$(CC) $(CFLAGS) -c $<
.cpp.o:
$(CXX) $(CPPFLAGS) -c $<
# end
这就是我编译 cuda_kernels.cu nvcc -c -arch sm_20 -lcuda -lcudart -lcusparse cuda_kernels.cu 的方式
这就是我得到的错误
upcg7.o: In function `upcg7ar':
/home/zhangmj/MF2005_MAKE/upcg7.f:731: undefined reference to `upcgc7_init_'
upcg7.o: In function `upcg7ap':
/home/zhangmj/MF2005_MAKE/upcg7.f:1272: undefined reference to `upcgc7_'
upcg7.o: In function `upcg7da':
/home/zhangmj/MF2005_MAKE/upcg7.f:1416: undefined reference to `upcgc7_final_'
upcgc.o: In function `UPCGC7':
upcgc.cpp:(.text+0xf6a): undefined reference to `SUPCGILU0A'
collect2: ld returned 1 exit status
make: [mf2005-GPU] Error 1 (ignored)
以下是upcg7.f(这不是我的代码,我从这里下载) https://github.com/jdhughes-usgs/modflow-2005-upcg/blob/master/code/src/UPCG/upcg7.f
以下是 upcgc.cpp 和 upcgc.h(这不是我的代码,我从这里下载) https://github.com/jdhughes-usgs/modflow-2005-upcg/blob/master/code/src/UPCG/ upcgc.cpp
**我的问题是 ** SUPCGILU0A 是 upcg7.f 中定义的子程序。从 C++ 程序 upcgc.cpp 调用子程序 SUPCGILU0A。upcgc7_init、upcgc7和upcgc7_final定义在upcgc.cpp中,这三个是从fortran程序upcg7.f中调用的。
我从我的研究中了解到,这些可能是链接器问题,或者 C++ 和 Fortran 需要相互转换一些函数/例程,但我无法弄清楚问题是什么。有没有人可能对问题所在有所了解?