Makefile文件和"搬迁具有无效的符号索引"错误 [英] Makefile and "relocation has invalid symbol index" error
问题描述
我试图写我的第一个Makefile文件。在项目中,我有这些文件:
I was trying to write my first makefile. In my project I have these files:
- 的main.c
- list.c
- list.h
- 的Makefile
有甚至没有函数定义或声明的任何人,只是简单的包括list.h
和清洁的主要测试编译过程。当我编译这些文件在控制台命令:
There is even no function definition or declaration in any of them, just simple include "list.h"
and clean main to test the compilation process. When I compile these files in console with command:
的gcc -std = C99 -Wall -Wextra的main.c list.c
一切都很好,但是当我用我的Makefile(Qt Creator中和国美终端)我得到了很多类似的错误:
everything is fine, but when I use my Makefile (in Qt Creator and Gome terminal) I'm getting a lot of errors like:
: - 1:错误:/usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info):搬迁0具有无效符号索引11
。
这是我的Makefile:
This is my Makefile:
CC=gcc
CFLAGS=-std=c99 -Wall -Wextra
LDFLAGS=
all: listtest
listtest: main.o list.o
$(CC) main.o list.o -o listtest
main.o: main.c
$(CC) $(CFLAGS) main.c
list.o: list.c
$(CC) $(CFLAGS) list.c
clean:
rm -rf *o listtest
这是我使用去创造一个makefile教程。有什么不对这个makefile,我该如何解决?
This is a makefile tutorial I was using to create it. What's wrong with this makefile and how can I fix it?
http://mrbook.org/tutorials/make/
推荐答案
您错过了 -c
在的.o
规则:
main.o: main.c
$(CC) -c -o main.o $(CFLAGS) main.c
list.o: list.c
$(CC) -c -o list.o $(CFLAGS) list.c
一个更好的规则是:
%.o : %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
此模式规则本质上是建立在内置规则的.o
从 .C
,见<一HREF =http://www.gnu.org/software/make/manual/make.html#Catalogue-of-Rules相对=nofollow>隐规则make的目录的。换句话说,你不需要编写任何上述规则。
This pattern rule is essentially the built-in rule for building .o
from .c
, see make's Catalogue of Implicit Rules. In other words, you don't need to write any of the above rules.
有一个更好的规则是:
%.o : %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ -MD -MP -MF ${@:.o=.d} $<
这将自动为您生成依赖关系。这些依赖关系必须被纳入生成文件(在随后的运行中):
This automatically generates dependencies for you. These dependencies need to be included into makefile (on subsequent runs):
-include $(wildcard *.d)
这篇关于Makefile文件和&QUOT;搬迁具有无效的符号索引&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!