macos 文件是为不受支持的文件格式构建的,这不是正在链接的体系结构 (x86_64)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10183053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
file was built for unsupported file format which is not the architecture being linked (x86_64)
提问by
I have a build file on OSX Lion
我在 OSX Lion 上有一个构建文件
VPATH = src include
CFLAGS ="-I include -std=gnu99"
hello: hello.o
gcc $^ -o $@
hello.o: hello.h hello.c
gcc $(CFLAGS) -c $< -o $@
But when I try and run this make file I get the following error
但是当我尝试运行这个 make 文件时,我收到以下错误
ld: warning: ignoring file hello.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I have tried using the flag -arch x86_64
but still get the same error.
我曾尝试使用该标志,-arch x86_64
但仍然出现相同的错误。
Running the arch
command gives: i386
.
运行arch
命令给出:i386
。
uname -a
tells me: Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64
uname -a
告诉我: Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64
I've also tried to add the switch -march=x86-64
as described in this answer file was built for i386 which is not the architecture being linked (x86_64) while compiling OpenCV2.2 for iOS 4.2 on Mac OSX 10.6but that hasn't worked for me.
在 Mac OSX 10.6 上为 iOS 4.2 编译 OpenCV2.2 时,我还尝试添加为 i386 构建的-march=x86-64
答案文件中所述的开关,这不是链接的架构(x86_64),但这对我不起作用。
The output from the command line is:
命令行的输出是:
gcc -I include -std=gnu99 -m64 -c include/hello.h -o hello.o
gcc -I include -std=gnu99 -m64 hello.o -o hello
ld: warning: ignoring file hello.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [hello] Error 1
采纳答案by Jonathan Leffler
- Remove all the object files.
Revise the makefile more like:
VPATH = src include CFLAGS = -I include -std=gnu99 -m64 CC = gcc LDLIBS = LDFLAGS = hello: hello.o $(CC) $(CFLAGS) $^ -o $@ hello.o: hello.c hello.h $(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS) $(LDLIBS)
- 删除所有目标文件。
修改 makefile 更像是:
VPATH = src include CFLAGS = -I include -std=gnu99 -m64 CC = gcc LDLIBS = LDFLAGS = hello: hello.o $(CC) $(CFLAGS) $^ -o $@ hello.o: hello.c hello.h $(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS) $(LDLIBS)
Note that I've macro-ized everything on the command lines. The CFLAGS are used in all compilations. They are not enclosed in double quotes. The -m64
option requests a 64-bit build; it shouldn't be necessary, but it makes it explicit. You don't yet need the LDFLAGS or LDLIBS macros (so you could omit them without causing yourself problems), but they show how you might proceed when you do need some libraries at link time.
请注意,我已经对命令行上的所有内容进行了宏化。CFLAGS 用于所有编译。它们没有用双引号括起来。该-m64
选项请求 64 位构建;它不应该是必要的,但它使它明确。您还不需要 LDFLAGS 或 LDLIBS 宏(因此您可以省略它们而不会给自己带来问题),但是它们显示了在链接时确实需要某些库时您可以如何进行。
For my own makefiles, I do things like:
对于我自己的 makefile,我会执行以下操作:
IFLAGS = -Iinclude
WFLAG1 = -Wall
WFLAG2 = -Werror
WFLAG3 = -Wextra
WFLAGS = $(WFLAG1) $(WFLAG2) $(WFLAG3)
OFLAGS = -g -O3
SFLAG1 = -std=c99
SFLAG2 = -m64
SFLAGS = $(SFLAG1) $(SFLAG2)
DFLAGS = # -Doptions
UFLAGS = # Set on make command line only
CFLAGS = $(SFLAGS) $(DFLAGS) $(IFLAGS) $(OFLAGS) $(WFLAGS) $(UFLAGS)
That way I can adjust just about any single argument to the C compiler on the command line. For example, to do 32-bit builds, I can run:
这样我就可以在命令行上调整 C 编译器的任何单个参数。例如,要进行 32 位构建,我可以运行:
make SFLAG2=-m32
Etc. The downside is I can never remember which xFLAGnoption affects which. However, a quick look at the makefile rectifies that, and I can change the compilation without modifying the makefile at all.
等等。缺点是我永远不记得哪个xFLAGn选项会影响哪个。然而,快速查看 makefile 可以纠正这一点,我可以在不修改 makefile 的情况下更改编译。
(I also often use CC="gcc -m64"
to force 64-bit compilations on other people's software.)
(我也经常用来CC="gcc -m64"
在其他人的软件上强制进行 64 位编译。)
回答by cheez
I had this problem when I accidentally included a .h file in an archive...
当我不小心在存档中包含一个 .h 文件时,我遇到了这个问题......
回答by user2657341
In my case, the -M option was creating this issue. I added this option to project dependencies but somehow it was causing issues.
就我而言,-M 选项造成了这个问题。我将此选项添加到项目依赖项中,但不知何故它导致了问题。