1. 程式人生 > >g++: cannot specify -o with -c or -S with multiple files 和nm: test.o: File format not reco 的原因和解決方案

g++: cannot specify -o with -c or -S with multiple files 和nm: test.o: File format not reco 的原因和解決方案

       最近寫makefile潦草不已, 於是就出現了g++: cannot specify -o with -c or -S with multiple files, 我們看案例:

       test.h:

void output();
       test.cpp:
#include <stdio.h>
#include "test.h"

void output()
{
	printf("c is good\n");
}
       編譯:
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的時候, -c不要指定多個檔案。 也是, 編譯時根本就不用加上test.h,   編譯器會自己去找的, 只要給定了目錄即可。

       原問題是在大型程式碼中的, 浪費我15分鐘啊。