title: Undefined Symbols when linking against a mixed C and Fortran in OS X 10.6.4
body: <p>I'm trying to compile a code (not mine) that consists of mixed Fortran and C source files, which are compiled into a library. This library can either be linked against directly, or (more usefully) driven from a python class. I have previously successfully built the code as 32-bit with g77 and gcc, but I've encountered a situation in which the code uses big chunks of memory, and needs to be 64-bit.</p>
  
  <p>I've attempted to build as both 64-bit only, or as a universal binary, with gfortran 4.2.3 (binary dist from the AT&amp;T R project) and the system gcc (4.2). The source files build correctly, but when I attempt to link against the library, I get many "Undefined Symbols" errors for a number of the Fortran functions. An nm on the library shows that the symbols appear to exist, but obviously the linker isn't finding them. </p>
  
  <p>Here are two (of many) of the compile commands (which produce no errors):</p>
  
  <pre><code>/usr/local/bin/gfortran -arch ppc -arch i386 -arch x86_64  -fPIC -fno-strength-reduce -fno-common -ff2c -Wall -c  lsame.f
  
  gcc -c -I/Users/keriksen/Research/atomic_data/fac -I/Users/keriksen/Research/atomic_data/fac/faclib -O2 -fPIC -fno-strength-reduce -fno-common pmalloc.c
  </code></pre>
  
  <p>And the link step, which bombs:</p>
  
  <pre><code>gcc -o sfac sfac.c stoken.c -I/Users/keriksen/Research/atomic_data/fac -I/Users/keriksen/Research/atomic_data/fac/faclib -O2 -fPIC -fno-strength-reduce -fno-common -L/Users/keriksen/Research/atomic_data/fac -lfac -lm -lgfortran -lgcc
  </code></pre>
  
  <p>A sample Undefined Symbol:</p>
  
  <pre><code>  "_acofz1", referenced from:
        _HydrogenicDipole in libfac.a(coulomb.o)
        _HydrogenicDipole in libfac.a(coulomb.o)
  </code></pre>
  
  <p>and the corresponding nm that shows that symbol exists:</p>
  
  <pre><code>    niobe:atomic_data/fac[14] nm libfac.a | grep acof
  
  0000000000000000 T _acofz1_
  0000000000002548 S _acofz1_.eh
                   U _acofz1
  </code></pre>
  
  <p>Am I doing something stupid, like not including a necessary switch to the linker, or is something more subtle going on here?</p>