Correct way to statically link in gfortran libraries on OSX

元气小坏坏 提交于 2019-12-03 01:02:44

I know this is very old tracker, but maybe somebody will be still interested in the solution that works.

Let's say we have code:

! fort_sample.f90
program main
  write (*,*) 'Hello'
  stop
end

First, compile the stuff:

gfortran -c -o fort_sample.o fort_sample.f90

Then, link stuff

ld -o ./fort_sample -no_compact_unwind \
-arch x86_64 -macosx_version_min 10.12.0 \
-lSystem \
/usr/local/gfortran/lib/libgfortran.a \
/usr/local/gfortran/lib/libquadmath.a \
/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a \
fort_sample.o

You can execute it

./fort_sample
 Hello

You can notice that quadmath is no longer there

> otool -L fort_sample
fort_sample:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.51.1)

I guess this is what you were looking for in a first place. No removing dylibs, no symbolic links, etc.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!