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

makefile的编写问题
OBJECTS   =   hello.o   main.o
TARGET     =   main

main:   main.o   hello.o
g++   main.o   hello.o   -o   main  
main.o:   main.cpp
g++   -c   main.cpp   -o   main.o
hello.o:   hello.cpp   hello.h
g++   -c   hello.cpp   -o   hello.o

上面是makefile的内容,为什么编译的时候老是报错?我的makefile文件,有什么问题,麻烦指出来,谢谢

linux:/home/cbtest/mytest   #   make   -f   ./makefile
./makefile:6:   ***   missing   separator.     Stop.

main.cpp中的内容如下,用到了hello.h
#include   "hello.h "
#include   <stdio.h>
#include   <iostream>

using   namespace   std;
int   main()
{
                cout   < <   "program   begin..... "   < <   endl;
                hello   hello1;
                hello1.sayHello();
                return   0;
}


------解决方案--------------------
在makefile中,凡是属于命令行的前面都要打上Tab键。
比如你的
main: main.o hello.o
g++ main.o hello.o -o main
应当改成
main: main.o hello.o
之后敲击enter键会令其一行。然后按Tab键,再写g++ main.o hello.o -o main

------解决方案--------------------
#makefile越短越好,不要太长了.
OFILES = \
main.o\
File1.o\
File2.o\
File3.o\
File4.o\
File5.o\
File6.o
# Compiler command name
CC = gcc

# Compiler flags applied to all files
# Optional flags: -D_VERBOSE -D_DEBUG
# -g puts debug symbols
#
CFLAGS = -Os -Wall -D_POSIX -D_DEBUG -I../ -I./ -I../path1 -I../path2 -I../path3 -I../path4 -I../path5 -g -lpthread -lm

# Search paths
VPATH = src: ./ ../ ../path1 ../path2 ../path3


# Builds all object files and executable
${EXENAME} : $(OFILES)
$(CC) $(CFLAGS) -o ${EXENAME} $(OFILES)

# Macro rule for all object files.
$(OFILES) : \
file1.h\
file2.h\
file3.h\
file4.h\
file5.h\
file6.h

# Clean up
clean :
rm -f $(OFILES)

------解决方案--------------------
-Os
优化大小. -Os使用所有的 "-O2 "优化中不会增加大小的功能. 它还可以进一步优化设计来减小代码的大小.
-Os屏蔽了下面的优化选项.
-falign-functions -falign-jumps -falign-loops
-falign-labels -freorder-blocks -freorder-blocks-and-partition
-fprefetch-loop-arrays -ftree-vect-loop-version