title: Makefile error when compiling with gfortran on Mac OS
body: <p>I run Mac OS X lion with the latest Xcode (4.3):</p>
  
  <pre><code>gfortran --version # -&gt; GNU Fortran (GCC) 4.6.1
  gcc --version # -&gt; i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658)
  </code></pre>
  
  <p>My makefile gives an error:</p>
  
  <pre><code>gfortran temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
  ld: duplicate symbol ___rng_MOD_uni in temp/testModules.o and temp/modules.o for architecture x86_64
  collect2: ld returned 1 exit status
  make: *** [arenatest] Error 1
  </code></pre>
  
  <p>I don't understand what the reason is, so I tried writing a build script that does the same thing, and surprisingly it works wonders. I want to have a makefile and NOT a script, so could anyone spot the difference? I am completely out of ideas.</p>
  
  <p>I know that there is a funky loop-replacement script for generating the .o objects in the right subdirectories. The build/compile-commands seem to match perfectly however. If there is a cleverer way of doing this, I'm open for suggestions.</p>
  
  <p>Script:</p>
  
  <pre><code>echo remove old files
  rm *.mod
  rm *.o
  rm -rf temp
  rm arenatest
  
  echo create directories and compile:
  mkdir -p temp
  gfortran -cpp -c ../modules/modules.f90 -o temp/modules.o -J../buildtest -I../buildtest
  gfortran -cpp -c ../modules/mathFunctions.f90 -o temp/mathFunctions.o -J../buildtest -I../buildtest
  gfortran -cpp -c testModules.f90 -o temp/testModules.o -J../buildtest -I../buildtest
  gfortran -cpp -c functionTest.f90 -o temp/functionTest.o -J../buildtest -I../buildtest
  
  echo do linking: gfortran -cpp temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
  gfortran temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
  
  echo DONE!
  </code></pre>
  
  <p>makefile: </p>
  
  <pre><code>PROGRAM = arenatest
  BUILDDIR = temp
  FC = gfortran
  SRC = ../modules/modules.f90 ../modules/mathFunctions.f90 testModules.f90 functionTest.f90
  OBJ = $(SRC:.f90=.o)
  OBJECTS = $(foreach var, $(OBJ), $(BUILDDIR)/$(lastword $(subst /, , $(var))) )
  FLAGS =-J../buildtest -I../buildtest
  
  
  all: buildtest
  
  buildtest: $(PROGRAM)
  
  build_message:
      @echo
      @echo sources:
      @echo $(SRC)
      @echo objects:
      @echo $(OBJECTS)
  
  clean:
      rm -rf temp
      rm arenatest
      rm *.mod
      rm *.o
  
  
  mkdir:
      @echo create directories and compile:
      mkdir -p temp
  
  # 
  # gfortran -cpp -c ../modules/modules.f90 -o temp/modules.o -J../buildtest -I../buildtest
  # gfortran -cpp -c ../modules/mathFunctions.f90 -o temp/mathFunctions.o -J../buildtest -I../buildtest
  # gfortran -cpp -c testModules.f90 -o temp/testModules.o -J../buildtest -I../buildtest
  # gfortran -cpp -c functionTest.f90 -o temp/functionTest.o -J../buildtest -I../buildtest
  # 
  $(OBJECTS) : $(SRC) | mkdir
      $(FC) -c $(FLAGS) $&lt; -o $@
  # link: #echo do linking: gfortran -cpp temp/modules.o temp/testModules.o temp/mathFunctions.o temp/functionTest.o -o arenatest
  $(PROGRAM): $(OBJECTS) | build_message
      $(FC) $(FLAGS) $(OBJECTS) -o $(PROGRAM)
  
  #echo DONE!
  </code></pre>