2
找到解决方案。请看下图:使文件无法正常工作?
我试图让我的makefile编译三个C程序转变成一个可执行文件,但我得到以下错误:
cachesim.o: could not read symbols: File in wrong format
是的,我使用的是使清洁我每次都使用它。 make文件是遵循
CC = gcc
CFLAGS = -Wall -m32 -O -g
all: cachesim cache trace_file_parser
gcc -o cachesim cachesim.o cache.o trace_file_parser.o
cachesim: cachesim.c
$(CC) -c -o cachesim.o cachesim.c $(CFLAGS)
cache: cache.c
$(CC) -c -o cache.o cache.c $(CFLAGS)
trace_file_parser: trace_file_parser.c
$(CC) -c -o trace_file_parser.o trace_file_parser.c $(CFLAGS)
clean:
rm -f *.o
我想不通这是为什么....
我使用使清洁每次。
试图编译:
[[email protected]] (34)$ make clean
rm -f *.o
[[email protected]] (35)$ ls
cache.c cache.h cachesim.c~ gcc_trace Makefile~ trace_file_parser.c
cache.c~ cachesim.c cache_structs.h Makefile strgen_trace trace_file_parser.h
[[email protected]] (36)$ make
gcc -c -o cachesim.o cachesim.c -Wall -m32 -O -g
gcc -c -o cache.o cache.c -Wall -m32 -O -g
gcc -c -o trace_file_parser.o trace_file_parser.c -Wall -m32 -O -g
gcc -o cachesim cachesim.o cache.o trace_file_parser.o
cachesim.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [all] Error 1
SOLUTION
CC = gcc
CFLAGS = -Wall -m32 -O -g
all: cachesim.c cache.c trace_file_parser.c
$(CC) -o cachesim cachesim.c cache.c trace_file_parser.c $(CFLAGS)
cachesim: cachesim.c
$(CC) -c -o cachesim.o cachesim.c $(CFLAGS)
cache: cache.c
$(CC) -c -o cache.o cache.c $(CFLAGS)
trace_file_parser: trace_file_parser.c
$(CC) -c -o trace_file_parser.o trace_file_parser.c $(CFLAGS)
clean:
rm -f *.o
我每次都使用make clean。 试图编译: – katiea
查看上面的更改 – katiea
哦。你使用'-m32'标志将目标文件编译为32位,但是你并没有在链接行上加上'-m32',所以它试图把程序作为一个64位程序连接起来,从而将32位'.o '文件格式错误。 – MadScientist