Linux GCC make文件的写法3
包含3个文件夹
目录组织结构如下:
inc/hello.h
main/main.c, Makefile
src/hello.c
文件内容如下:
hello.h:
void hello(char name[]);
main.c:
#include <stdio.h>
#include "../inc/hello.h"
// The second hello.h should in ""
int main()
{
hello("GCC");
printf("Haha Linux Ubuntu!\n");
return 0;
}
其中,第二个包含文件,hello.h,必须要用"",如果用<>则gcc只会到系统目录下去搜索,不会到本当前目录下搜索
就是""在用户目录下,<>在系统目录下,这个在windows上不严格, 在linux里似乎很严格
Makefile版本1:
# String declaration
objects = main.o hello.o
# Command
app : $(objects)
cc -o app $(objects)
main.o : main.c hello.h
cc -c main.c
hello.o : hello.c stdio.h
cc -c ../src/hello.c
# Search paths
vpath %.h /usr/include ../inc
vpath %.c ../src
# Clean the intermediate files
.PHONY : clean
clean :
rm app $(objects)
貌似vpath只对 %.o : 后面的有影响,下面的cc -c没有作用
**************************
确实是这样的,
%.o : %.c %.h,这句话是make的语句,而下面的
cc -c %.c,这句话是gcc的语句,
而vpath和VPATH设定的是make的搜索路径,对gcc的搜索路径没有影响。
gcc设置搜索路径为:
cc -c main.c -Iinclude
**************************
Makefile版本2:
# String declaration
objects = main.o hello.o
# Command
app : $(objects)
cc -o app $(objects)
main.o : main.c hello.h
cc -c main.c
hello.o : ../src/hello.c stdio.h
cc -c ../src/hello.c
# Search paths
vpath %.h /usr/include ../inc
#vpath %.c ../src
# Clean the intermediate files
.PHONY : clean
clean :
rm app $(objects)
hello.c:
#include <stdio.h>
void hello(char name[])
{
printf("Hello %s!\n", name);
}
相关文档:
Linux上TCP丢失小包不可见的解决
作者:千里孤行(http://blog.csdn.net/yanghehong)
有网友在做一个Linux上的客户端碰到这样的问题:
我们在Linux下开发一个网络客户端程序(服务器是不可修改的),不断向服务器不定期发送一些很小的包(一般只有几十字节),现在出现这种情况:大部分包正常发送,但是当无线Modem ......
在各种Linux分发版中,大多数都已经默认集成了snmpd,比如在suse10中,你可以这样开启snmpd:
suse10:~ # /etc/init.d/snmpd start
如果没有默认安装,你要做的就是自己来编译snmpd,按照下边的步骤,非常简单。
编译和安装
对于Linux平台,我们推荐使用Net-SNMP,它实现了标准的SNM ......
引:
Linux操作系统是由Linus Torvalds先生在1991年创建的,之后不断获得互联网上众多程序员的自愿支持,经过十几年的发展,如今已经成为继Windows之后的第二大电脑操作系统软件。
你是否对Linux有充分的了解呢?作为一种平台,Linux首先获得了沉溺于某种癖好之士和黑客们的
青睐。Linux操作系统是由Linus
Torvalds先生 ......
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
......