在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)
-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)
相关文章推荐
- Linux预处理、编译、汇编、链接和运行的过程(包括一些基本的命令)
- linux编译使用链接库
- Q115:Linux系统下CodeBlocks对PBRT-V3进行编译和调试
- 如何在Linux下用C/C++语言操作数据库sqlite3(很不错!设计编译链接等很多问题!)
- 在Linux下安装android开发环境并以USB调试方式链接手机进行开发e
- MFC编译选项设置与MSVCRT链接版本的对应关系总结
- Linux 2.6.19.x 内核编译配置选项简介
- linux 编译,链接和加载
- qt 中 c 编译选项/链接库如何链接
- (转载) Linux 2.6.19.x 内核编译配置选项简介
- Linux下编译链接库路径
- C/C++ 跨平台交叉编译、静态库/动态库编译、MinGW、Cygwin、CodeBlocks使用原理及链接参数选项
- VC编译\链接\运行:包含文件、包含库lib、包含动态库dll的一些问题
- Linux 内核编译配置选项简介(转)
- 编译RT-tests进行Linux实时性测试
- Linux下预处理,编译,汇编,链接过程及gdb的使用
- 【内核】linux2.6版本内核编译配置选项(二)
- Linux下编译android source中的一些小心得
- Linux 2.6.19.x 内核编译配置选项简介(五)
- 【Jenkins】linux下Jenkins集成ant进行编译并发送结果