![](/img/trans.png)
[英]C project suddenly not compiling on macOS "building for macOS-x86_64 but attempting to link with file built for unknown-arm64"
[英]Building for macOS-x86_64 but attempting to link with file built for macOS-arm64
我想在继续使用 TextMate 文本编辑器的同时使用 GNU 科学库 (GSL),但在 TextMate 中编译代码时遇到了一些编译问题。
首先,我使用 M1 Mac (Ventura 13.0.1),GSL 库安装在:/usr/local/include/gsl
为了尝试编译,我采用了最基本的示例,并使用非常通用的 MakeFile 对其进行了编译。
代码:
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int
main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
MakeFile:
CC = gcc
EXEC = PROG
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
CFLAGS = -g -Wall
LIBS = -lm -lgsl -lgslcblas -I/usr/local/include/gsl
RM = rm -rf
all : $(EXEC)
%.o : %.c
$(CC) -o $@ -c $<
$(EXEC) : $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) && time ./$(EXEC) && make clean
.PHONY : clean
clean :
rm -rf $(EXEC) && rm -rf *.o
值得庆幸的是,如果我用 macOS 终端编译,一切都很好。 我还尝试使用应用程序内终端在 VS Code 中编译我的代码,它工作正常。
但是,当我尝试使用 MakeFile 包(见下文)通过 TextMate 编译我的程序时遇到了一些错误。 经过几个小时的阅读并试图弄清楚,我认为问题在于 TextMate 的编译器与 macOS 编译器不同,并且由于 Rosetta,它在 macOS 终端上运行良好。 我根本不是专家,所以我非常不确定我说的是什么。
这是错误代码:
ld: warning: ignoring file /usr/local/lib/libgslcblas.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
...
Undefined symbols for architecture x86_64:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [PROG] Error 1
我还尝试通过 Homebrew 安装库并更改 MakeFile 中的 PATH,但是在 TextMate 中,我有相同的错误消息。
我在这里发帖的原因是我找不到任何适用于 TextMate Editor 的解决方案,因为它可以与 macOS 的本机终端一起正常工作。
那么,有没有办法在 TextMate 中解决这个问题(也许在 MakeFile 中?直接在 TextMate 应用程序中?)? 再一次,我不是专家,我真的不知道如何解决这个问题......
编辑:我试图通过使用以下命令编译文件来重新安装库:
./configure CC ="gcc -arch x86_64"
./make
...
现在,它可以在 TextMate 上运行,但不再适用于 macOS 终端……我在 macOS 终端上有:
ignoring file /usr/local/lib/libgsl.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
...
Undefined symbols for architecture arm64:
...
ld: symbol(s) not found for architecture arm64
这与我之前的完全相反。 有没有一种方法可以编译我的程序的库?
提前致谢!
好的,我找到了适合我的解决方案。
为此,当您通过 GSL package 的./configure
安装库时,您将必须精确确定多个体系结构,然后在终端中键入的命令应该是:
sudo./configure CC="gcc -arch arm64 -arch x86_64"
通过这样做,您应该能够在任何 IDE 中使用我上面编写的适当的 MakeFile 编译您的程序,因为该库是为多种体系结构构建的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.