views:

261

answers:

2

Hi,

I would like to compile fortran code on mac such that it does not depend on any shared library. Ultimately, I want to be able to send the binary to other people and for it to just work (provided the processor has the right architecture). I noticed that g95 and ifort have a -static flag, which does not work on mac.

If I consider the following program:

program test
  print *,'hello world'
end program test

and compile it with

ifort -static-libgcc -static-intel test.f90

The resulting binary still depends on a few shared libraries:

valinor:tmp tom$ otool -L a.out 
a.out:
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 103.0.0)
    /usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version 315.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 124.1.1)

So is there a way to properly compile fortran code such that it does not depend on any shared library on mac?

+1  A: 

Static libraries are difficult on Mac OS X by design.

See this post for more information on static binaries on Mac OS X.

In theory, you could build static libraries yourself and link against them. You'd have to fetch the C runtime library from Darwin and compile it, libgcc, and so on, statically. It will work, but it might involve some work.

csl
+2  A: 

The short answer is: you don't actually want full static linking on Mac OS X. Linking in static versions of some product-specific libraries is fair and good, but the system shared libraries are just that: shared libraries that you'll always find on any Mac, with guaranteed compatibility from Apple.

PS: You can get rid of libgcc_s by actually specifying -static-libgcc on your commande-line. Not that it's worth doing any way, but...

FX