OSX Mavericks导致“无法在生成多个输出文件时指定-o” [英] OSX Mavericks causes "cannot specify -o when generating multiple output files"

查看:124
本文介绍了OSX Mavericks导致“无法在生成多个输出文件时指定-o”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



** clang:错误:无法指定-o当生成多个输出时文件
**



makefile是:

  SHELL = / bin / sh 
CC = gcc
CFLAGS = -Wall -O3 -funroll-all-loops
EXEC = program
SRC = $(EXEC).c file1。 c file2.c file3.c file4.c
OBJ = $(SRC:.c = .o)
LIB = $(SRC:.c = .h)

全部:$(EXEC)

$(EXEC):$(OBJ)$(LIB)
$(CC)-o $ @ $ ^ $(LDFLAGS)-lm

%.o:%.c $(LIB)
$(CC)-o $ @ -c $< $(CFLAGS)




  • gcc被重定向到clang, t知道这是否会导致所描述的错误。
  • gcc已安装

  • 我不知道如何取消重定向以再次测试。
  • li>
  • 我看到这篇文章: Makefile; gcc不工作?相信小牛是负责任的,但我并不真正理解这个问题及其解决方法



感谢您的关注

解决方案

从行中移除 $(LIB)

  $(EXEC):$(OBJ)$(LIB)

定义 LIB 的方式,它的值为 program.h file1.h file2.h file3。 h file4.h 。这有两个效果。首先,它说 $(EXEC),它是程序取决于 .h 文件。但是,程序仅直接取决于 .o 文件。 程序不直接在其版本中使用 .h 文件,因此程序的依赖关系不应该包含 .h 文件。

其次,<$ c $命令中的c> $ ^ 列出了目标所依赖的所有文件。这将所有 .o .h 文件传递给编译器。当编译器看到几个 .h 列出的文件时,它会指出几个源文件将被编译,因此会产生多个目标文件。



当您从此规则的依赖项中移除 $(LIB)时, .h 文件不会在命令中列出。然后编译器只会看到几个 .o 文件,所以它会知道它将多个对象链接到一个可执行文件中,并且不会尝试编译源文件。


Since I installed mavericks on my mac, I can't compile some of my programs.

**clang: error: cannot specify -o when generating multiple output files **

The makefile is :

SHELL = /bin/sh
CC = gcc
CFLAGS = -Wall -O3 -funroll-all-loops
EXEC = program
SRC = $(EXEC).c file1.c file2.c file3.c file4.c
OBJ = $(SRC:.c=.o)
LIB = $(SRC:.c=.h)

all: $(EXEC)

$(EXEC): $(OBJ) $(LIB)
    $(CC) -o $@ $^ $(LDFLAGS) -lm

%.o: %.c $(LIB)
    $(CC) -o $@ -c $< $(CFLAGS)

  • gcc is redirected to clang, but I don't know if this causes the described error.
  • gcc is installed
  • I don't know how to cancel this redirection to test again.
  • I saw this post : Makefile; gcc not working? Believe Mavericks is responsible but I don't really understand the problem and its resolution

Thanks for your attention

解决方案

Remove $(LIB) from the line:

$(EXEC): $(OBJ) $(LIB)

The way LIB is defined, it has the value program.h file1.h file2.h file3.h file4.h. This has two effects.

First, it says that $(EXEC), which is program, depends on the .h files. However, program depends directly only on the .o files. program does not directly use the .h files in its build, so the dependencies for program should not include the .h files.

Second, the $^ in the command says to list all the files that the target depends on. This passes all the .o and .h files to the compiler. When the compiler sees several .h files listed, it figures that several source files will be compiled, and therefore several object files will be produced.

When you remove $(LIB) from the dependencies in this rule, the .h files will not be listed in the command. Then the compiler will see only several .o files, so it will know it is linking several objects into one executable and will not attempt to compile source files.

这篇关于OSX Mavericks导致“无法在生成多个输出文件时指定-o”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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