mingw下使用g++ -MM编译代码,链接时报错,请高手帮忙!
我的makefile如下:
CC = g++ -g
OBJECTS = test_cpp_main.o test_cpp_example.o
all: testcpp
COMPILING_MSG=@echo "Compiling the $< ..."
LINK_MSG=@echo "Link the $< ..."
testcpp:${OBJECTS}
${LINK_MSG}
${CC} -o $@ ${OBJECTS}
%.o: %.cpp
${COMPILING_MSG}
${CC} -c -O2 -MM -Wall $< -o $@ //去掉-MM就能编译成功
.PHONY:clean
clean:
rm -f *.o
rm -f *.obj
rm -f testcpp.exe
rm -f *.lis
为了解决编译时,只修改了头文件,不会编译源代码的问题,我在makefile中加入-MM,但是编译就报错,编译结果如下:
Compiling the test_cpp_main.cpp ...
g++ -g -c -O2 -MM -Wall test_cpp_main.cpp -o test_cpp_main.o
Compiling the test_cpp_example.cpp ...
g++ -g -c -O2 -MM -Wall test_cpp_example.cpp -o test_cpp_example.o
Link the test_cpp_main.o ...
g++ -g -o testcpp test_cpp_main.o test_cpp_example.o
d:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/ld.exe:test_cpp_main.o: file format not recognized; treating as link
d:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/ld.exe:test_cpp_main.o:1: syntax error
collect2: ld returned 1 exit status
make: *** [testcpp] Error 1