title: gfortran: symbol(s) not found for architecture x86_64
body: <p>I am trying since a week to compile a code written in F90 and C. I keep getting an undefined symbols error. I will try to give as much information as I can but the package includes hundreds of files so it is a bit difficult to give all the details. This is the Makefile</p>
  
  <pre><code>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 $&lt; $(&lt;F:.F90=.F90)
      $(FPP_COMMAND) $(&lt;F:.F90=.F90)
      rm -f $(&lt;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
  </code></pre>
  
  <p>The Makefile includes this other file</p>
  
  <pre><code># 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'
  </code></pre>
  
  <p>The compilation looks fine apart from a couple of warnings. Then in the linking phase something goes wrong. The last lines of the make read:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>Thanks</p>