日期:2014-05-16  浏览次数:20657 次

makefile 当有c++/c的头文件时如何解决
有一个main.cpp   包含了first.h文件和iostream.h文件
一个first.cpp文件包含了first.h文件
如果上面没有iostream.h文件,我可以搞定makefile,刚刚初识makefile,看了一点介绍,大概了解了依赖,编译,链接等用法。但是有了iostream.h后就一直有问题,是不是还要加路径什么的啊,请高人指点
我的makefile文件:
all:main.o   first.o   ;cc   -o   main.o   first.o
main.o:main.cpp   first.h   ;cc   -c   main.cpp
first.o:first.cpp   first.h;cc   -c   first.cpp

用make执行时会有下面这个错误:
cc   -o   main.o   first.o
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x18):   In   function   `_start ':
../sysdeps/i386/elf/start.S:77:   undefined   reference   to   `main '
collect2:   ld   returned   1   exit   status


------解决方案--------------------
要加include路径。编译器的命令行参数应该是:-I。
------解决方案--------------------
改用g++
或者加入-lstdc++参数
------解决方案--------------------
把main.cpp first.cpp first.h放在同一目录下,
makefile如下:

all: main.o first.o
(TAB)g++ -o test main.o first.o
main.o: main.cpp
(TAB)g++ -c main.cpp
first.o: first.cpp
(TAB)g++ -c first.cpp
clean:
(TAB)rm -rf test
(TAB)rm -rf *.o

试过了,可以....
不然你用anjuta直接生成