LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 803|回复: 3

求助:向各位大哥请教一个 makefile 问题,谢谢!

[复制链接]
发表于 2006-7-4 12:07:54 | 显示全部楼层 |阅读模式
我自己写了一个,可是不行,各位大哥再帮我看看

te.h
void func1();
void func2();
void func3();



test1.c
#include <stdio.h>
#include <te.h>

void func1()
{
  printf("test1test1");
}  
int main()
{
         printf("test1");
         func1();
         return 1;
}





test2.c
#include <stdio.h>
#incldue <te.h>

void func2()
{
  printf("test2");
}  



test3.c
#include <stdio.h>
#incldue <te.h>

void func3()
{
  printf("test3");
}




我自己写的 makefile 文件为:
mypro1:test1.o test2.o test3.o
        gcc -o mypro1 test1.o test2.o test3.o
test1.o:test1.c te.h
        gcc -c -o test1.o test1.c
test2.o:test2.c te.h
        gcc -c -o test2.o test2.c
test3.o:test3.c te.h
        gcc -c -o test3.o test3.c


然后保存为:
mypro1.mk


然后在终端里执行;
[root@localhost linuxss]# make -f mypro1.mk

make: *** Warning: File `mypro1.mk' has modification time in the future (2006-07-04 11:49:35 > 2006-07-04 11:45:06.434738)
gcc -c -o test1.o test1.c
test1.c:2:16: te.h: 没有那个文件或目录
test1.c:13:2: warning: no newline at end of file
make: *** [test1.o] Error 1


这是我的程序有问题吗?
我是有 <te.h> 的啊?


还是我的 makefile 文件写错了呢?

谢谢!



各位大哥,我是错在哪里呢?

谢谢!
发表于 2006-7-4 13:48:06 | 显示全部楼层
假设*.h在当前目录下./include , *.c/cpp在当前目录下./source, *.o放到当前目录./source下。

  1. #  Options for compilers
  2. CC                = gcc
  3. CCPLUS        = g++
  4. OPTS            = -fno-rtti -fno-exceptions

  5. # Directories.
  6. BASE_DIR     =.
  7. INCS             =-I$(BASE_DIR)./include      // Path of includes.
  8. CFLAGS        +=$(INCS) $(OPTS)
  9. LDFLAGS       = -pthread -rdynamic        // Thread and dynamic libs inside yours
  10. OBJS             =$(BASE_DIR)./source           // Paht of objects

  11. LIBS              = -ldl

  12. all:: bin-name   
  13. clean::
  14.         rm -f $(OBJS) bin-name            // Note: begin of the line with TAB NOT others

  15. bin-name: $(OBJS)
  16.         $(CCPLUS) -o $@ $(LDFLAGS) $(OJBS)

  17. # Rules to compiler C/C++ files.
  18. $(BASE_DIR)source/%.o : $(BASE_DIR)source/%.cpp
  19.         $(CCPLUS) -c (CFLAGS) $< $@
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-7-4 15:08:16 | 显示全部楼层
汗一下楼主 include都写错了。。
你的te.h不是在include里吧。。要是和.c在一下用"te.h"
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-6 08:26:08 | 显示全部楼层
大哥们真是太牛了!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表