Makefile Compiling Issue for Mixed C++ and Fortran Program -
this makefile :
program = mf2005-gpu.f # define fortran compile flags f90flags= -g -fopenmp f90= gfortran # define c compile flags # -d_uf defines unix naming conventions 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 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 object files make 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 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
this how compile cuda_kernels.cu nvcc -c -arch sm_20 -lcuda -lcudart -lcusparse cuda_kernels.cu
this errors
upcg7.o: in function `upcg7ar': /home/zhangmj/mf2005_make/upcg7.f:731: undefined reference `upcgc7_init_' upcg7.o: in function `upcg7ap': /home/zhangmj/mf2005_make/upcg7.f:1272: undefined reference `upcgc7_' upcg7.o: in function `upcg7da': /home/zhangmj/mf2005_make/upcg7.f:1416: undefined reference `upcgc7_final_' upcgc.o: in function `upcgc7': upcgc.cpp:(.text+0xf6a): undefined reference `supcgilu0a' collect2: ld returned 1 exit status make: [mf2005-gpu] error 1 (ignored)
following upcg7.f (this not code, download here) https://github.com/jdhughes-usgs/modflow-2005-upcg/blob/master/code/src/upcg/upcg7.f
following upcgc.cpp , upcgc.h (this not code, download here) https://github.com/jdhughes-usgs/modflow-2005-upcg/blob/master/code/src/upcg/upcgc.cpp
**my question ** supcgilu0a subroutine defined in upcg7.f. , subroutine supcgilu0a called c++ program upcgc.cpp. upcgc7_init, upcgc7 , upcgc7_final defined in upcgc.cpp, , these 3 called fortran program upcg7.f.
i understand research these linker issues,or c++ , fortran need translate function/routine other, cannot figure out problem is. there out there might have insight issue is?
if upcgc7 routines reside in c code, not have trailing underscore. best way deal make use of iso_c_binding interface in fortran , declare interfaces these routines.
Comments
Post a Comment