日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

幾個(gè)好用的makefile 幾乎可以不用修改(轉(zhuǎn))

 ONLY_影 2015-01-13

Makefile

       用 makefile 來(lái)編譯工程,對(duì)很多朋友來(lái)說(shuō)都是一件麻煩而痛苦的事情,這里我寫了幾個(gè) makefile ,專門提供給那些曾經(jīng)被 makefile 困擾的朋友,根據(jù)生成的目標(biāo)文件不同,我將 makefile 分成了三份:生成可執(zhí)行文件的 makefile ,生成靜態(tài)鏈接庫(kù)德 makefile ,生成動(dòng)態(tài)鏈接庫(kù)的 makefile 。

       這些 makefile 都很簡(jiǎn)單,一般都是一看就會(huì)用,用法也很容易,只需要把它們拷貝到你的代碼的同一目錄下,然后就可以使用 make 來(lái)生成目標(biāo)文件了。

       是不是真的有這么神奇?呵呵,你自己用用就知道了。

       當(dāng)然,如果要用到什么庫(kù)文件,你還需要修改一些編譯參數(shù),這個(gè)可以對(duì)照我轉(zhuǎn)載的另一篇文章《 GNU make 指南》。

       下面是三個(gè) makefile 的源代碼:

 

       1 、生成可執(zhí)行文件的 makefile

######################################

#

# Generic makefile

#

# by Coon Xu

# email: coonxu@126.com

#

# Copyright (c) 2005 Coon Xu

# All rights reserved.

# No warranty, no liability;

# you use this at your own risk.

#

# You are free to modify and

# distribute this without giving

# credit to the original author.

#

######################################

 

 

#source file

# 源文件,自動(dòng)找所有 .c 和 .cpp 文件,并將目標(biāo)定義為同名 .o 文件

SOURCE  := $(wildcard *.c) $(wildcard *.cpp)

OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))

 

#target you can change test to what you want

# 目標(biāo)文件名,輸入任意你想要的執(zhí)行文件名

TARGET  := test

 

#compile and lib parameter

# 編譯參數(shù)

CC      := gcc

LIBS    :=

LDFLAGS:= 

DEFINES:=

INCLUDE:= -I.

CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)

CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H

 

 

#i think you should do anything here

# 下面的基本上不需要做任何改動(dòng)了

.PHONY : everything objs clean veryclean rebuild

 

everything : $(TARGET)

 

all : $(TARGET)

 

objs : $(OBJS)

 

rebuild: veryclean everything

               

clean :

    rm -fr *.so

    rm -fr *.o

   

veryclean : clean

    rm -fr $(TARGET)

 

$(TARGET) : $(OBJS) 

    $(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

 

       2 、生成靜態(tài)鏈接庫(kù)的 makefile

######################################

#

# Generic Static Library makefile

#

# by Coon Xu

# email: coonxu@126.com

#

# Copyright (c) 2005 Coon Xu

# All rights reserved.

# No warranty, no liability;

# you use this at your own risk.

#

# You are free to modify and

# distribute this without giving

# credit to the original author.

#

######################################

 

#target you can change test to what you want

# 共享庫(kù)文件名, lib*.a

TARGET  := libtest.a

 

#compile and lib parameter

# 編譯參數(shù)

CC      := gcc

AR      = ar

RANLIB  = ranlib

LIBS    :=

LDFLAGS:= 

DEFINES:=

INCLUDE:= -I.

CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)

CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H

 

#i think you should do anything here

# 下面的基本上不需要做任何改動(dòng)了

 

#source file

# 源文件,自動(dòng)找所有 .c 和 .cpp 文件,并將目標(biāo)定義為同名 .o 文件

SOURCE  := $(wildcard *.c) $(wildcard *.cpp)

OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))

 

.PHONY : everything objs clean veryclean rebuild

 

everything : $(TARGET)

 

all : $(TARGET)

 

objs : $(OBJS)

 

rebuild: veryclean everything

               

clean :

    rm -fr *.o

   

veryclean : clean

    rm -fr $(TARGET)

 

$(TARGET) : $(OBJS) 

    $(AR) cru $(TARGET) $(OBJS)

    $(RANLIB) $(TARGET)

 

       3 、生成動(dòng)態(tài)鏈接庫(kù)的 makefile

######################################

#

# Generic Share Library makefile

#

# by Coon Xu

# email: coonxu@126.com

#

# Copyright (c) 2005 Coon Xu

# All rights reserved.

# No warranty, no liability;

# you use this at your own risk.

#

# You are free to modify and

# distribute this without giving

# credit to the original author.

#

######################################

 

#target you can change test to what you want

# 共享庫(kù)文件名, lib*.so

TARGET  := libtest.so

 

#compile and lib parameter

# 編譯參數(shù)

CC      := gcc

LIBS    :=

LDFLAGS:= 

DEFINES:=

INCLUDE:= -I.

CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)

CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H

SHARE   := -fPIC -shared -o

 

#i think you should do anything here

# 下面的基本上不需要做任何改動(dòng)了

 

#source file

# 源文件,自動(dòng)找所有 .c 和 .cpp 文件,并將目標(biāo)定義為同名 .o 文件

SOURCE  := $(wildcard *.c) $(wildcard *.cpp)

OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))

 

.PHONY : everything objs clean veryclean rebuild

 

everything : $(TARGET)

 

all : $(TARGET)

 

objs : $(OBJS)

 

rebuild: veryclean everything

               

clean :

    rm -fr *.o

   

veryclean : clean

    rm -fr $(TARGET)

 

$(TARGET) : $(OBJS) 

    $(CC) $(CXXFLAGS) $(SHARE) $@ $(OBJS) $(LDFLAGS) $(LIBS)

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多