当前位置: 技术问答>linux和unix
如何编译多文件的源代码?
来源: 互联网 发布时间:2015-07-12
本文导语: 现在有一程序,由5个文件构成(.c和.h)。代码肯定是正确的,在os400上跑着。现在我做了些修改,准备先在redhat9下测试。我已完全安装gcc。 问题一,以下头文件在redhat9中都有吗? #include #include #include #include #...
现在有一程序,由5个文件构成(.c和.h)。代码肯定是正确的,在os400上跑着。现在我做了些修改,准备先在redhat9下测试。我已完全安装gcc。
问题一,以下头文件在redhat9中都有吗?
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
问题二,习惯了windows下VC集成编译环境,不知在linux下如何将多个文件编译成执行文件。
问题一,以下头文件在redhat9中都有吗?
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
问题二,习惯了windows下VC集成编译环境,不知在linux下如何将多个文件编译成执行文件。
|
问题一 都有
问题二 写makefile
CC = gcc
CFLAGS =
INCDIR = -I./h ../h
LIBS =
BINNAME = test
COBJS = a1.o a2.o ./dir1/a3.o
.SUFFIXES: .o .c
.c.o: ; $(CC) $(CFLAGS) -c $*.c
#--------------------- Dependency starts here -------------------
all: $(COBJS)
$(CC) $(LIBS) -o $(BINNAME) $(COBJS)
clean: /tmp
-rm -fr $(COBJS)
-rm -fr $(BINNAME)
# DO NOT DELETE
问题二 写makefile
CC = gcc
CFLAGS =
INCDIR = -I./h ../h
LIBS =
BINNAME = test
COBJS = a1.o a2.o ./dir1/a3.o
.SUFFIXES: .o .c
.c.o: ; $(CC) $(CFLAGS) -c $*.c
#--------------------- Dependency starts here -------------------
all: $(COBJS)
$(CC) $(LIBS) -o $(BINNAME) $(COBJS)
clean: /tmp
-rm -fr $(COBJS)
-rm -fr $(BINNAME)
# DO NOT DELETE
|
a.c b.c
gcc -o exefile a.c b.c
gcc -o exefile a.c b.c
|
makefile 写完后用make命令就可以了。
依照楼主的意思makefile可以这样写:
[tab]gcc -o exefile a.c b.c
redha下好像没有那么vc这样的IDE,呵呵。
依照楼主的意思makefile可以这样写:
[tab]gcc -o exefile a.c b.c
redha下好像没有那么vc这样的IDE,呵呵。
|
makefile的语法不是很复杂的,记得前一阵这里有人贴了个写makefile的,不错,找找应该还在的。
有可以直接给你生成makefile的东西,好像叫makeconf吧,记不太清,可以为你直接写好makefile,不过好像效率不高。其实自己写并不复杂,用我们老师的话,你连几百个文件的代码都写了,还在乎写个makefile吗:)
有可以直接给你生成makefile的东西,好像叫makeconf吧,记不太清,可以为你直接写好makefile,不过好像效率不高。其实自己写并不复杂,用我们老师的话,你连几百个文件的代码都写了,还在乎写个makefile吗:)
|
关于makefile,看《跟我一起写makefile》:
http://www.vczx.com/forum/attachment.php?s=f5bf01c9b3f2f1945117e415720bc353&postid=3391
http://www.vczx.com/forum/attachment.php?s=f5bf01c9b3f2f1945117e415720bc353&postid=3391
|
1、有
2、学习写makefile吧
2、学习写makefile吧
|
makefile,拷个模板照着套就行了