编译“静态”文件Mac 上的 Fortran 二进制文件

发布于 2024-08-07 01:52:24 字数 716 浏览 4 评论 0原文

我想在 mac 上编译 fortran 代码,使其不依赖于任何共享库。最终,我希望能够将二进制文件发送给其他人并使其正常工作(前提是处理器具有正确的架构)。我注意到 g95 和 ifort 有一个 -static 标志,它在 mac 上不起作用。

如果我考虑以下程序:

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

并用 编译它

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

生成的二进制文件仍然依赖于一些共享库:

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)

那么有没有一种方法可以正确编译 fortran 代码,使其不依赖于 mac 上的任何共享库?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海夕 2024-08-14 01:52:24

静态库在 Mac OS X 上的设计是很困难的。

有关 Mac OS 上的静态二进制文件的更多信息,请参阅这篇文章 X.

理论上,您可以自己构建静态库并链接它们。您必须从 Darwin 获取 C 运行时库并静态编译它、libgcc 等。它会起作用,但可能需要一些工作。

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.

往事风中埋 2024-08-14 01:52:24

简短的答案是:您实际上并不希望在 Mac OS X 上进行完全静态链接。在某些特定于产品的库的静态版本中进行链接是公平且良好的,但系统共享库就是这样:您将始终使用的共享库可在任何 Mac 上找到,并且具有 Apple 的兼容性保证。

PS:您可以通过在命令行上实际指定 -static-libgcc 来摆脱 libgcc_s 。并不是说它值得做任何事情,但是......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文