相关疑难解决方法(0)

如何在OS X上进行静态链接

我正在尝试链接到OS X上的静态库.我-static在gcc命令中使用了该标志,但是我收到以下错误消息:

ld_classic: can't locate file for: -lcrt0.o
collect2: ld returned 1 exit status

我查看了手册页,它的内容如下:

除非所有库(包括libgcc.a)都已使用-static编译,否则此选项在Mac OS X上不起作用.由于既没有提供libSystem.dylib的静态版本也没有提供crt0.o,因此该选项对大多数人没用.

有没有其他方法可以链接到这个静态库?

macos linker static-libraries

51
推荐指数
4
解决办法
3万
查看次数

在 macOS arm64 架构上使用 x86 库和 OpenMP

我有一台 MacBook M1,并在我的机器上安装了一个针对 x86 / Intel 架构编译的库。我有一些使用 OpenMP 的源代码。我想使用 clang 编译器编译我的代码并将我的可执行文件链接到 x86 库。

我可以按照此处的说明,使用与brew一起分发的clang实现来编译没有x86依赖项的源代码。

然而,当我尝试使用-arch x86_64参数进行编译并链接到 x86 库时,我发现 clang 尝试将我的可执行文件链接到为 arm64 架构构建的 OpenMP 库。

是否可以在 MacBook M1 上安装为 x86 架构构建 OpenMP 库的 clang 版本?

以下是我使用当前设置时遇到的错误示例,即使未链接到 x86 库也是如此。

源代码:

#include <omp.h>
int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

调用编译器:

/opt/homebrew/opt/llvm/bin/clang++ -arch x86_64 omp_ex.cpp \ 
    -L/opt/homebrew/opt/llvm/lib -Wl,-rpath,/opt/homebrew/opt/llvm/lib \
    -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
Run Code Online (Sandbox Code Playgroud)

错误信息:

ld: in '/opt/homebrew/opt/llvm/lib/libunwind.dylib', building for macOS-x86_64 but attempting to link with file built for macOS-arm64
clang-12: error: linker command …
Run Code Online (Sandbox Code Playgroud)

c++ macos openmp clang apple-m1

8
推荐指数
1
解决办法
7777
查看次数

静态-libgfortran在库构建中

我正在尝试构建一个只有静态引用libgfortran(最好libgcc也是)的库.

但是,如果我使用链接器标志

-static -lgfortran -static-libgfortran -static-libgcc
Run Code Online (Sandbox Code Playgroud)

在OS XI得到

ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用

-shared -lgfortran -static-libgfortran
Run Code Online (Sandbox Code Playgroud)

我明白了

Undefined symbols for architecture x86_64:
  "_quadmath_snprintf", referenced from:
      _write_float in libgfortran.a(write.o)
  "_strtoflt128", referenced from:
      __gfortrani_convert_real in libgfortran.a(read.o)
      __gfortrani_convert_infnan in libgfortran.a(read.o)
Run Code Online (Sandbox Code Playgroud)

如果我使用的话,一切编译都很好(但有一个动态链接到libgfortran和libgcc)-dynamiclib -lgfortran.

似乎gcc不是在OS X上静态构建的.

如何构建我的库以便最终用户不需要安装gfortran或gcc?

我正在使用gcc的macports版本,但我准备使用gfortran/gcc的另一个经销商,如果它允许我这样做的话.

linker gcc fortran static-linking

4
推荐指数
1
解决办法
5095
查看次数