您的位置:首页 > 运维架构 > Linux

在linux中进行编译链接的一些选项

2011-05-29 15:39 197 查看
gcc编译:

-L :

-Ldir

Add directory dir
to the list of directories to be searched for -l.

-I :

-I dir

Add the directory dir to the list of directories to be searched for header

files. Directories named by -I are searched before the standard system

include directories.

If the directory dir is a standard system include

directory, the option is ignored to ensure that the default search order for

system directories and the special treatment of system headers are not

defeated .

-c :生成cpp文件对应的*.o文件。

-D:

TEST_FLAG = -Dprotected=public -Dprivate=public -U__inner

在test目录的makefile中,和源代码的test目录中,添加此项,可将保护、私有的编译为公有的。

ar打包:

ar -rv
libmovie.a $(OBJECTS)

ld链接:

-l:

-larchive

--library=archive

Add archive file archive to the list of files to link
. This option may be

used any number of times. ld will search its path-list for occurrences of

"libarchive.a" for every archive specified.

On systems which support shared libraries, ld may also search for libraries

with extensions other than ".a". Specifically, on ELF and SunOS systems, ld

will search a directory for a library with an extension of ".so" before

searching for one with an extension of ".a". By convention, a ".so" exten-

sion indicates a shared library.

可以参考下面的btest中的makefile:

CXXFLAGS=-fPIC -g -finline-functions -Wall -W -Winline -pipe -Wreturn-type -Wtrigr

aphs -Wformat -Wparentheses -Wpointer-arith -Werror -Wno-unused-parameter -D_GNU_S

OURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D__VERSION_ID__=

"/"1.0.0.0/""

14 CFLAGS=$(CXXFLAGS)

15 INCPATH= -I../include -I.. -I$(LOCAL_CVS_ROOT)/com/btest/gtest/output/include -I.

16 DEP_LDFLAGS= -L$(LOCAL_CVS_ROOT)/../btestUse/movie/src -L$(LOCAL_CVS_ROOT)/com/bte

st/gtest/output/lib -L. -L../lib


17 DEP_LDLIBS= -lpthread -lstdc++ -lgtest -lgtest_main -lmovie

18 CXX=g++

19 CC = gcc

20

21 PATTERN=test*.cpp

22 TESTFILES=$(wildcard $(PATTERN))

23 EXE=$(basename $(TESTFILES))

24 all : $(EXE)

25 $(EXE) : % : %.cpp

26 $(CXX) $^ -o $@ $(CXXFLAGS) $(CFLAGS) $(INCPATH) $(DEP_LDFLAGS) $(DEP_LDLIBS)

27 .PHONY: list clean

28 list:

29 @echo $(EXE)

30 clean:

31 rm $(EXE)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: