我正在尝试一周以来编译用F90和C编写的代码。我一直收到一个未定义的符号错误。我会尽量提供尽可能多的信息,但包中包含数百个文件,所以提供所有细节有点困难。这是Makefile
include paths.mk
include include.mk.$(OPT)
#------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------#
# Double check that the "LOWO" flags have been set. In case they have not, clone the #
# standard options. LOWO stands for LOWer Optimisation, and these flags are used for a #
# subroutines that are taking several hours to compile with ifort-13 (ed_state_vars.f90 #
# and a few others). #
#------------------------------------------------------------------------------------------#
ifeq ($(F_LOWO_OPTS),)
F_LOWO_OPTS = $(F_OPTS)
endif
#------------------------------------------------------------------------------------------#
#----- Compiler commands. -----------------------------------------------------------------#
INCLUDES = $(PAR_INCS) -I$(ED_INCS) $(HDF5_INCS) $(MPI_INCS)
F90_COMMAND = $(F_COMP) -c $(F_OPTS) $(INCLUDES) $(PAR_DEFS)
F90_LOWO_COMMAND = $(F_COMP) -c $(F_LOWO_OPTS) $(INCLUDES) $(PAR_DEFS)
FPP_COMMAND = $(F_COMP) -c -DUSE_INTERF=$(USE_INTERF) -DUSENC=$(USENC) -D$(CMACH) \
-DUSE_HDF5=$(USE_HDF5) -DUSE_COLLECTIVE_MPIO=$(USE_COLLECTIVE_MPIO) \
-DUSE_MPIWTIME=$(USE_MPIWTIME) $(F_OPTS) $(INCLUDES) $(PAR_DEFS)
FPP_LOWO_COMMAND = $(F_COMP) -c -DUSE_INTERF=$(USE_INTERF) -DUSENC=$(USENC) -D$(CMACH) \
-DUSE_HDF5=$(USE_HDF5) -DUSE_COLLECTIVE_MPIO=$(USE_COLLECTIVE_MPIO) \
-DUSE_MPIWTIME=$(USE_MPIWTIME) $(F_LOWO_OPTS) $(INCLUDES) $(PAR_DEFS)
CXX_COMMAND = $(C_COMP) -c $(C_OPTS) -D$(CMACH) $(HDF5_INCS) $(INCLUDES) $(PAR_DEFS)
#------------------------------------------------------------------------------------------#
#----- Define archive and executable names. -----------------------------------------------#
EXE=$(BASE)/ed_$(ED_VERSION)-$(OPT)
LIBMODEL=$(BASE)/ed_$(ED_VERSION)-$(OPT).a
#------------------------------------------------------------------------------------------#
include objects.mk
#----- Define targets. --------------------------------------------------------------------#
all:
make gendep
make $(EXE)
make $(EXE)
make $(EXE)
make $(EXE)
make $(EXE)
gendep:
@echo ""
./generate_deps.sh $(ED_ROOT)
@echo === Finished dependencies ===
$(EXE): $(LIBMODEL) $(MAINOBJ)
@echo ""
$(LOADER) -o $(EXE) edmain.o $(LOADER_OPTS) $(INCLUDES) $(LIBMODEL) $(HDF5_LIBS) \
$(PAR_LIBS) $(NC_LIBS) $(LIBS) $(LOADER_OPTS)
@echo ""
@echo Finished building === $(EXE)
@echo ""
$(MAINOBJ): $(MAIN)
@echo ""
cp -f $< $(<F:.F90=.F90)
$(FPP_COMMAND) $(<F:.F90=.F90)
rm -f $(<F:.F90=.F90)
$(LIBMODEL): $(OBJ_MODEL)
$(ARCHIVE) $(LIBMODEL) $(OBJ_MODEL)
FORCE:
install:
@echo ""
ln -fs `pwd`/$(EXE) ../run/$(BASE)
ln -fs `pwd`/$(EXE) ../test/$(BASE)
@echo ""
clean:
@echo ""
rm -f $(LIBMODEL) $(EXE) *.o *.mod *.F90 *.f90 *.stb *.d dependency.mk
rm -f ../$(EXE) ../$(LIBMODEL)
touch dependency.mk
@echo ""
#----- Define rules -----------------------------------------------------------------------#
include rules.mk
Makefile包含此其他文件
# Define make (gnu make works best).
MAKE=/usr/bin/make
# libraries.
BASE=$(ED_ROOT)/build/
# Activate appropriate parts below, comment out others.
# HDF 5 Libraries
# ED2 HAS OPTIONAL HDF 5 I/O
# If you wish to use this functionality specify USE_HDF5=1
# and specify the location of the include directory
# library files. Make sure you include the zlib.a location too.
USE_HDF5=1
HDF5_INCS=-I/opt/local/include
HDF5_LIBS= -L/opt/local/lib -lhdf5 -lhdf5_fortran -lz -L/opt/local/lib/libgcc/ -lstdc++ -lm
#---------------------------------------------------------------
# If you have a version of hdf5 compiled in parallel, then you
# may benefit from collective I/O, then use this flag = 1
# Otherwise, set it to zero.
USE_COLLECTIVE_MPIO=0
#---------------------------------------------------------------
# interface ----------------------------------------------------
# This should be 1 unless you are running with -gen-interfaces.
# Interfaces usually make the compilation to crash when the
# -gen-interfaces option are on, so this flag bypass all
# interfaces in the code.
USE_INTERF=1
# MPI_Wtime. ---------------------------------------------------
# If USE_MPIWTIME=1, then it will use MPI libraries to compute
# the wall time (the only double-precision intrinsic). In case
# you don't have it, leave USE_MPIWTIME=0, in which case it will
# use a simpler, single-precision function.
USE_MPIWTIME=0
#----------------- MAC_OS_X (Leopard) ---- gfortan/gcc ---------------
CMACH=MAC_OS_X
F_COMP=gfortran
C_COMP=gcc
LOADER=gfortran
##################################### COMPILER OPTIONS #####################################
#------------------------------------------------------------------------------------------#
USE_INTERF=1
F_OPTS= -O0 -ffree-line-length-none
C_OPTS= -O0 -DLITTLE -stdlib=libstdc++
F_LOWO_OPTS= -O0 -ffree-line-length-none
LOADER_OPTS= -O0 -ffixed-line-length-none
#------------------------------------------------------------------------------------------#
# For IBM,HP,SGI,ALPHA,LINUX use these:
ARCHIVE=ar rs
# For NEC SX-6
#ARCHIVE=sxar rs
# For SUN,CONVEX
#ARCHIVE=ar r'
除了几个警告之外,编辑看起来很好。然后在链接阶段出现问题。 make的最后几行是:
ar rs /Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt.a allometry.o an_header.o
!!!all other object files listed!!!
therm_lib.o therm_lib8.o twostream_rad.o update_derived_props.o utils_c.o utils_f.o vegetation_dynamics.o
ar: creating archive /Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt.a
/opt/local/bin/ranlib: file: /Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt.a(consts_coms.o) has no symbols
/opt/local/bin/ranlib: file: /Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt.a(ed_max_dims.o) has no symbols
cp -f /Users/manfredo/Desktop/ED2/ED/src/driver/edmain.F90 edmain.F90
gfortran -c -DUSE_INTERF=1 -DUSENC= -DMAC_OS_X -DUSE_HDF5=1 -DUSE_COLLECTIVE_MPIO=0 -DUSE_MPIWTIME=0 -O0 -ffree-line-length-none -I/Users/manfredo/Desktop/ED2/ED/src/include -I/opt/local/include edmain.F90
rm -f edmain.F90
gfortran -o /Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt edmain.o -O0 -ffixed-line-length-none -I/Users/manfredo/Desktop/ED2/ED/src/include -I/opt/local/include /Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt.a -L/opt/local/lib -lhdf5 -lhdf5_fortran -lz -L/opt/local/lib/libgcc/ -lstdc++ -lm \
-O0 -ffixed-line-length-none
Undefined symbols for architecture x86_64:
"_calchydrosubsurface_", referenced from:
_ed_model_ in ed_2.1-opt.a(ed_model.o)
"_calchydrosurface_", referenced from:
_ed_model_ in ed_2.1-opt.a(ed_model.o)
"_canopy_photosynthesis_", referenced from:
___rk4_driver_MOD_rk4_timestep in ed_2.1-opt.a(rk4_driver.o)
!!!all other similar errors!!!
"_writehydro_", referenced from:
_ed_model_ in ed_2.1-opt.a(ed_model.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[1]: *** [/Users/manfredo/Desktop/ED2/ED/build//ed_2.1-opt] Error 1
make: *** [all] Error 2
由于
答案 0 :(得分:1)
这是一个链接器错误。您似乎没有链接到包含_calchydrosubsurface_
的.o文件或库中。在不知道您使用的源代码或库的情况下,很难帮助您,但告诉您要查找的内容:
搜索包含 calchydrosubsurface 的源代码或库;找到后,请确保正确导出符号(nm <object file>
),并确保链接到make文件中的符号。