在OSX上静态链接gfortran库的正确方法 [英] Correct way to statically link in gfortran libraries on OSX

查看:442
本文介绍了在OSX上静态链接gfortran库的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要分发的fortran程序,所以我想在gfortran库中静态链接.

I've a fortran program I'd like to distribute, so I'd like to statically link in the gfortran libraries.

如果我使用以下标志编译程序:

If I compile the program with the following flags:

gfortran -o myprog -static-libgfortran -static-libgcc  myprog.f

otool告诉我它在大多数gofrtran库中都是静态链接的,但不是libquadmath:

otool tells me it's statically linked in most of the gofrtran libraries, but not libquadmath:

otool -L myprog

/usr/local/gfortran/lib/libquadmath.0.dylib (compatibility version 1.0.0, current v
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

有一个静态的libquadmath库/usr/local/gfortran/lib/libquadmath.a,但是我尝试的每个链接行总是以完整的静态链接(OSX不支持)或动态链接到libquadmath结束.

There is a static libquadmath library /usr/local/gfortran/lib/libquadmath.a, but every link line I tried always either ended up with a full static link (which isn't supported on OSX) or a dynamic link to libquadmath.

我设法通过从/usr/local/gfortran/lib/中删除libquadmath.0.dylib和libquadmath.dylib来创建所需的文件,然后链接程序提取静态库.

I've managed to create what I want by removing libquadmath.0.dylib and libquadmath.dylib from /usr/local/gfortran/lib/, and the linker then pulls in the static library.

但是,至少可以这样说,这似乎有些笨拙.

However, this seems somewhat clunky to say the least.

有人可以建议一种更优雅的方式吗?

Can anyone suggest a more elegant way of doing this?

谢谢!

推荐答案

我知道这是一个非常老的跟踪器,但是也许有人会对有效的解决方案感兴趣.

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

假设我们有代码:

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

首先,编译内容:

gfortran -c -o fort_sample.o fort_sample.f90

然后,链接东西

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

您可以执行

./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)

我想这就是您最初要寻找的东西.无需删除dylib,无符号链接等.

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

这篇关于在OSX上静态链接gfortran库的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆