最近写makefile, 碰到了nm: test.o: File format not recognized这个错误, 一起看看:
test.h:
void output();
test.cpp:
#include <stdio.h>
#include "test.h"
void output()
{
printf("c is good\n");
}
编译:
xxxxxx:~/mkfile> g++ -c test.cpp test.h -o test.o
xxxxxx:~/mkfile> nm test.o
nm: test.o: File format not recognized
xxxxxx:~/mkfile>
奇怪了吧? 原因是多了test.h文件, 根本没必要啊, 编译器会自动去找的, 只要你指定了目录即可。 如果把test.h和test.cpp的顺序调换, 则提示:
xxxxxx:~/mkfile> g++ -c test.h test.cpp -o test.o
g++: cannot specify -o with -c or -S with multiple files
xxxxxx:~/mkfile>
这一点, 我们在前面已经说过了。
看来, 有-o的时候, 你再去搞-c指定多个文件, 那就是天大的坑。