dpkg默认编译选项修改
⑴ 如何设置NDK的编译选项
1. 概述
首先回顾一下 Android NDK 开发中,Android.mk 和 Application.mk 各自的职责。
Android.mk,负责配置如下内容:
(1) 模块名(LOCAL_MODULE)
(2) 需要编译的源文件(LOCAL_SRC_FILES)
(3) 依赖的第三方库(LOCAL_STATIC_LIBRARIES,LOCAL_SHARED_LIBRARIES)
(4) 编译/链接选项(LOCAL_LDLIBS、LOCAL_CFLAGS)
Application.mk,负责配置如下内容:
(1) 目标平台的ABI类型(默认值:armeabi)(APP_ABI)
(2) Toolchains(默认值:GCC 4.8)
(3) C++标准库类型(默认值:system)(APP_STL)
(4) release/debug模式(默认值:release)
由此我们可以看到,本文所涉及的编译选项在Android.mk和Application.mk中均有出现,下面我们将一个个详细介绍。
2. APP_ABI
ABI全称是:Application binary interface,即:应用程序二进制接口,它定义了一套规则,允许编译好的二进制目标代码在所有兼容该ABI的操作系统和硬件平台中无需改动就能运行。(具体的定义请参考 网络 或者 维基网络 )
由上述定义可以判断,ABI定义了规则,而具体的实现则是由编译器、CPU、操作系统共同来完成的。不同的CPU芯片(如:ARM、Intel x86、MIPS)支持不同的ABI架构,常见的ABI类型包括:armeabi,armeabi-v7a,x86,x86_64,mips,mips64,arm64-v8a等。
这就是为什么我们编译出来的可以运行于Windows的二进制程序不能运行于Mac OS/linux/Android平台了,因为CPU芯片和操作系统均不相同,支持的ABI类型也不一样,因此无法识别对方的二进制程序。
而我们所说的“交叉编译”的核心原理也跟这些密切相关,交叉编译,就是使用交叉编译工具,在一个平台上编译生成另一个平台上的二进制可执行程序,为什么可以做到?因为交叉编译工具实现了另一个平台所定义的ABI规则。我们在Windows/Linux平台使用Android NDK交叉编译工具来编译出Android平台的库也是这个道理。
这里给出最新 Android NDK 所支持的ABI类型及区别:
那么,如何指定ABI类型呢?在 Application.mk 文件中添加一行即可:
APP_ABI := armeabi-v7a //只编译armeabi-v7a版本APP_ABI := armeabi armeabi-v7a //同时编译armeabi,armeabi-v7a版本APP_ABI := all //编译所有版本
3. LOCAL_LDLIBS
Android NDK 除了提供了Bionic libc库,还提供了一些其他的库,可以在 Android.mk 文件中通过如下方式添加依赖:
LOCAL_LDLIBS := -lfoo
其中,如下几个库在 Android NDK 编译时就默认链接了,不需要额外添加在 LOCAL_LDLIBS 中:
(1) Bionic libc库
(2) pthread库(-lpthread)
(3) math(-lmath)
(4) C++ support library (-lstdc++)
下面我列了一个表,给出了可以添加到“LOCAL_LDLIBS”中的不同版本的Android NDK所支持的库:
下面是我总结的一些常用的CFLAGS编译选项:
(1)通用的编译选项
-O2 编译优化选项,一般选择O2,兼顾了优化程度与目标大小
-Wall 打开所有编译过程中的Warning
-fPIC 编译位置无关的代码,一般用于编译动态库
-shared 编译动态库
-fopenmp 打开多核并行计算,
-Idir 配置头文件搜索路径,如果有多个-I选项,则路径的搜索先后顺序是从左到右的,即在前面的路径会被选搜索
-nostdinc 该选项指示不要标准路径下的搜索头文件,而只搜索-I选项指定的路径和当前路径。
--sysroot=dir 用dir作为头文件和库文件的逻辑根目录,例如,正常情况下,如果编译器在/usr/include搜索头文件,在/usr/lib下搜索库文件,它将用dir/usr/include和dir/usr/lib替代原来的相应路径。
-llibrary 查找名为library的库进行链接
-Ldir 增加-l选项指定的库文件的搜索路径,即编译器会到dir路径下搜索-l指定的库文件。
-nostdlib 该选项指示链接的时候不要使用标准路径下的库文件
(2) ARM平台相关的编译选项
-marm -mthumb 二选一,指定编译thumb指令集还是arm指令集
-march=name 指定特定的ARM架构,常用的包括:-march=armv6, -march=armv7-a
-mfpu=name 给出目标平台的浮点运算处理器类型,常用的包括:-mfpu=neon,-mfpu=vfpv3-d16
-mfloat-abi=name 给出目标平台的浮点预算ABI,支持的参数包括:“soft”, “softfp” and “hard”
⑵ Delphi的命令行编译命令
Borland出品的Delphi,有着闪电般的编译速度,但是在界面控件使用较多、工程项目较大的时候,编译一个工程仍需要一段时间,打开庞大的Delphi IDE,也需要时间。其实,在一个工程开发结束,调试完成之后的Release编译,完全可以用命令行来执行,因为Delphi的编译器参数不像C++编译器那样复杂。
笔者把Delphi联机手册中关于命令行编译(command-line compiler)的几篇主题作了翻译,希望对Delphi开发人员有帮助。
目录
1. Command-line compiler
命令行编译器
2. Command-line compiler options
命令行编译器选项
3. Compiler directive options
编译器指令选项
4. Compiler mode options
编译模式选项
5. DCC32.CFG file
编译器配置文件DCC32.CFG
6. Debug options
调试选项
7. Directory options
目录选项
8. IDE command-line options
IDE命令行选项
9. Generated files
几个IDE自动生成的文件介绍
Command-line compiler
命令行编译器
Delphi's command-line compiler (dcc32.EXE) lets you invoke all the functions of the IDE compiler (DELPHI32.EXE) from the DOS command line (see IDE command-line options. Run the command-line compiler from the DOS prompt using the syntax:
Delphi’s命令行编译器(dcc32.exe)允许你从DOS命令行方式(参照:IDE命令行选项)实现IDE编译器(delphi32.exe)的所有功能。用DOS命令运行命令行编译器语法如下:
dcc32 [options] filename [options]
dcc32 [选项] [文件名] [选项]
where options are zero or more parameters that provide information to the compiler and filename is the name of the source file to compile. If you type dcc32 alone, it displays a help screen of command-line options and syntax.
零或多个参数给编译器提供信息,文件名指定需要编译的源文件名。如果你单独输入dcc32,它会显示一个关于命令行编译的选项和语法的屏幕。
If filename does not have an extension, the command-line compiler assumes .dpr, then .pas, if no .dpr is found. If the file you're compiling to doesn't have an extension, you must append a period (.) to the end of the filename.
如果文件名没有扩展名,命令行编译器会查找扩展名为.dpr的同名文件,如果找不到,则查找扩展名为.pas的同名文件。如果你的源文件确实没有扩展名,你需要在文件名的末尾添加(.)。
If the source text contained in filename is a program, the compiler creates an executable file named filename.EXE. If filename contains a library, the compiler creates a file named filename.DLL. If filename contains a package, the compiler creates a file named filename.BPL. If filename contains a unit, the compiler creates a unit file named filename.dcu.
如果指定的源文件是一个工程文件,编译器会创建一个扩展名为.EXE的同名可执行文件。如果指定的源文件是一个库文件,编译器创建一个扩展名为.DLL的同名动态链接库文件。如果指定的源文件是一个包文件,编译器会创建一个扩展名为.BPL的同名包。如果指定的源文件是一个单元文件,编译器会创建一个扩展名为.dcu的目标代码文件。
You can specify a number of options for the command-line compiler. An option consists of a slash (/) or immediately followed by an option letter. In some cases, the option letter is followed by additional information, such as a number, a symbol, or a directory name. Options can be given in any order and can come before or after the file name.
你可以为命令行编译器指定多个参数。一个参数包含一个破折号“-”(或“/”)和紧跟着的一个选项字符构成。通常情况下,选项字符后面会跟一些附加的信息,如一个数字、一个符号、一个目录等。选项可以是任意顺序并且可以在源文件名前面或后面。
Command-line compiler options
命令行编译选项
The IDE lets you set various options through the menus; the command-line compiler gives you access to these options using the slash (/) delimiter. You can also precede options with a hyphen (-) instead of a slash (/), but those options that start with a hyphen must be separated by blanks. For example, the following two command lines are equivalent and legal:
IDE允许你使用菜单来设置各种编译选项,而命令行编译器允许你使用字符“/”作为分隔符来设定这些编译选项。你也可以使用连字符“-”来代替“/”,但是用“-”引出的参数之间必须用空格隔开。例如,下面两个命令都是等同的也是合法的:
DCC -IC:\DELPHI -DDEBUG SORTNAME -$R- -$U+
DCC /IC:\DELPHI/DDEBUG SORTNAME /$R-/$U+
The first command line uses hyphens with at least one blank separating options. The second uses slashes and no separation is needed.
第一个编译命令用“-”引出参数,且参数之间有多个空格分隔。第二个编译命令用“/”引出参数,参数之间不必要分隔。
The following table lists the command-line options. In addition to the listed options, all single-letter compiler directives can be specified on the command line, as described in Compiler directive options.
下列表中列出所有的命令行参数。在附加的选项列表中,所有的单字符编译器指令都可以在命令行编译中使用,详情请参照:编译器指令。
Option Description
选项 描述
Aunit=alias 设置单元别名
B 编译所有单元
CC 编译控制台程序
CG 编译图形界面程序
Ddefines 编译条件符号定义
Epath 可执行文件输出路径
Foffset 查找运行期间错误
GD 生成完整.Map文件
GP 生成.Map文件Public段
GS 生成.Map文件Segment段
H 输出提示信息
Ipaths 文件包含路径
J 生成.Obj目标文件
JP 生成C++类型.Obj目标文件
Kaddress Set image base address
LEpath 包.BPL文件输出路径
LNpath .dcp文件输出路径
LUpackage 使用运行期间包列表
M 编译有改动的源文件
Npath dcu/dpu文件输出目录
Opaths .Obj文件(汇编目标代码文件)路径
P 按8.3格式文件名查找
Q 安静模式
Rpaths 资源文件(.RES)路径
TXext 目标文件扩展名
Upaths 单元文件路径
V 为Turbo Debugger生成调试信息文件
VN 以.Giant格式生成包含命名空间的调试信息文件(将用于C++Builder)
VR 生成调试信息文件.rsm
W 输出警告信息
Z Disable implicit compilation
$directive Compiler directives
--Help 显示编译选项的帮助。同样的,如果你在命令行单独输入dcc32,也会显示编译选项的帮助。
--version 显示产品名称和版本
Compiler directive options
编译器指令选项
Delphi supports the compiler directives described in Compiler directives. The $ and D command-line options allow you to change the default states of most compiler directives. Using $ and D on the command line is equivalent to inserting the corresponding compiler directive at the beginning of each source file compiled.
Delphi支持用编译器指令关键字描述的编译器指令。使用“$”和“D”命令行选项可以改变所有的默认编译器状态。用“$”和“D”命令行选项等同于在源文件的前面添加编译器指令。
Switch directive option
编译器指令选项开关
The $ option lets you change the default state of all of the switch directives. The syntax of a switch directive option is $ followed by the directive letter, followed by a plus (+) or a minus (-). For example:
“$”允许你改变每一种编译器指令默认状态。编译器指令的语法是“$”后紧跟一个指令字符,再跟一个“-”或“+”。例如:
dcc32 MYSTUFF -$R-
compiles MYSTUFF.pas with range-checking turned off, while:
不使用边界检查编译MYSTUFF.pas单元:
dcc32 MYSTUFF -$R+
compiles it with range checking turned on. Note that if a {$R+} or {$R-} compiler directive appears in the source text, it overrides the -$R command-line option.
使用界面检查编译MYSTUFF.pas单元。如果将编译器指令{$R+}或{$R-}添加到源文件的开始,它将覆盖从命令行传入的参数。
You can repeat the -$ option in order to specify multiple compiler directives:
你可以用多个“$”来指定多个编译器指令,如:
dcc32 MYSTUFF -$R--$I--$V--$U+
Alternately, the command-line compiler lets you write a list of directives (except for $M), separated by commas:
命令行编译器允许作用逗号分隔的编译器指定列表,如:
dcc32 MYSTUFF -$R-,I-,V-,U+
只需要用一个“$”符号。
Only one dollar sign ($) is needed.
注意,因为$M的格式不一样,你不能在逗号分隔的指令列表中使用$M
Note that, because of its format, you cannot use the $M directive in a list of directives separated by commas.
Conditional defines option
条件编译选项
The -D option lets you define conditional symbols, corresponding to the {$DEFINE symbol} compiler directive. The -D option must be followed by one or more conditional symbols separated by semicolons (;). For example, the following command line:
“-D”选项允许你定义一个编译条件,符合你用{$DEFINE symbol}定义的编译器指令。“-D”选项后必须跟随一或多个用分号分隔的编译条件符号,如下命令:
dcc32 MYSTUFF -DIOCHECK;DEBUG;LIST
defines three conditional symbols, iocheck, debug, and list, for the compilation of MYSTUFF.pas. This is equivalent to inserting:
定义了三个编译条件符号:IOCHECK,DEBUG,LIST,用于MYSTUFF.pas单元中。这等同于在源文件中插入以下语句:
{$DEFINE IOCHECK}
{$DEFINE DEBUG}
{$DEFINE LIST}
at the beginning of MYSTUFF.pas. If you specify multiple -D directives, you can concatenate the symbol lists. Therefore:
如果你指定了多个“-D”选项,你可以联接它们,如下:
dcc32 MYSTUFF -DIOCHECK-DDEBUG-DLIST
is equivalent to the first example.
等同于第一个例子。
Compiler mode options
编译模式选项
A few options affect how the compiler itself functions. As with the other options, you can use these with either the hyphen or the slash format. Remember to separate the options with at least one blank.
有几个选项能影响编译器自身的功能。像其它选项一个,你可以使用“/”或“-”的格式。别忘了用至少一个空格分隔这些选项。
Make (-M) option
选项(-M)
The command-line compiler has built-in MAKE logic to aid in project maintenance. The -M option instructs command-line compiler to check all units upon which the file being compiled depends. Using this option results in a much quicker compile time.
命令行编译器使用构造逻辑的方式来维护工程。“-M”选项指示编译器检查所有与编译文件相关联的文件。用这个参数会导致编译时间增大。
A unit is recompiled under the following conditions:
一个源文件在下列情况下会重新编译:
The source file for that unit has been modified since the unit file was created.
源文件被创建以来被修改过;
用“$I”指令包含的任何文件,用“$L”包含的任何.Obj文件,或用“$R”关联的任何资源文件.Res,比源文件中的要新;
Any file included with the $I directive, any .OBJ file linked in by the $L directive, or any .res file referenced by the $R directive, is newer than the unit file.
The interface section of a unit referenced in a uses statement has changed.
单元接口部分interface的uses段有改动。
Units compiled with the -Z option are excluded from the make logic.
在单元编译时指令“-Z”在构造逻辑期不被接受。
If you were applying this option to the previous example, the command would be:
如果你在上一个例子中使用这个指令,编译命令就应该是:
dcc32 MYSTUFF -M
Build all (-B) option
编译所有 选项(-B)
Instead of relying on the -M option to determine what needs to be updated, you can tell command-line compiler to update all units upon which your program depends using the -B option. You can't use -M and -B at the same time. The -B option is slower than the -M option and is usually unnecessary.
用于取代要知道哪些单元需要更新-M的选项,你可以使用-B选项来更新所有你的程序中关联的单元。你不能在程序中同时使用-M和-B。选项-B比-M速度更慢,而且它并不是必需的。
If you were using this option in the previous example, the command would be
如果你在前一个例子中使用这个参数,编译命令就应该是:
dcc32 MYSTUFF -B
Find error (-F) option
查找错误 选项(-F)
When a program terminates e to a runtime error, it displays an error code and the address at which the error occurred. By specifying that address in a -Faddress option, you can locate the statement in the source text that caused the error, provided your program and units were compiled with debug information enabled (via the $D compiler directive).
当一个程序由于运行期间错误而终止时,它会显示一个错误号和错误地址在错误发生时。用-Faddress选项来指定错误地址,你在源文件中能找到引发错误的位置,如果你的程序和单元编译时附加了调试信息(使用$D编译器指令)。
In order for the command-line compiler to find the runtime error with -F, you must compile the program with all the same command-line parameters you used the first time you compiled it.
为了命令行编译器能用-F选项查找运行期间错误,你必须传递与第一次编译时相同的指令列表。
As mentioned previously, you must compile your program and units with debug information enabled for the command-line compiler to be able to find runtime errors. By default, all programs and units are compiled with debug information enabled, but if you turn it off, using a {$D-} compiler directive or a -$D- option, the command-line compiler will not be able to locate runtime errors.
先前提到过,你的程序和单元必须启用调试信息,命令行编译器才能查找运行期间错误。默认情况下,所有的程序和单都是启用调试信息的,除非你用{-D}或-$D-指令关闭它,这样,命令行编译器就不能查找运行期间错误了。
Use packages (-LU) option
使用包(-LU)选项
Use the -LU option to list additional runtime packages that you want to use in the application being compiled. Runtime packages already listed in the Project Options dialog box need not be repeated on the command line.
使用-LU选项来在编译时添加你应用程序中要用到的运行期间包。运行期间包已经在“工程选项”对话框中列举的,不必再在命令行中添加。
Disable implicit compilation (-Z) option
(此选项在delphi6.0/7.0中有不同描述,在此不作翻译)
The -Z option prevents packages and units from being implicitly recompiled later. With packages, it is equivalent to placing {$ IMPLICITBUILD OFF} in the .dpk file. Use -Z when compiling packages that provide low-level functionality, that change infrequently between builds, or whose source code will not be distributed.
Target file extension (-TX) option
目标文件扩展名(-TX)选项
The -TX option lets you override the default extension for the output file. For example,
选项-TX允许你改写默认的输出文件扩展名。例如:
dcc32 MYSTUFF -TXSYS
generates compiled output in a file called MYSTUFF.SYS.
生成的将是一个叫做MYSTUFF.SYS的文件。
Quiet (-Q) option
安静模式(-Q)选项
The quiet mode option suppresses the printing of file names and line numbers ring compilation. When the command-line compiler is invoked with the quiet mode option
安静模式选项禁止在编译时显示文件名及代码行数,如果命令行编译器调用这个选项的话。
dcc32 MYSTUFF -Q its output is limited to the startup right message and the usual statistics at the end of compilation. If any errors occur, they will be reported.
它的输出仅限于起始时行版权信息以及结尾的统计信息。当然,如果发生错误,它也会输出。
DCC32.CFG file
DCC32.CFG配置文件
You can set up a list of options in a configuration file called DCC32.CFG, which will then be used in addition to the options entered on the command line. Each line in configuration file corresponds to an extra command-line argument inserted before the actual command-line arguments. Thus, by creating a configuration file, you can change the default setting of any command-line option.
你可以设置一个编译选项列表到一个叫做DCC32.CFG的配置文件中,它将用于编译时附加到命令行参数后。配置文件的每一行都相当于一个额外的命令行参数插入到实际的命令行参数前(注意,是实际参数前)。因而,你可以使用这个配置文件改变一些命令行参数的默认设置。
The command-line compiler lets you enter the same command-line option several times, ignoring all but the last occurrence. This way, even though you've changed some settings with a configuration file, you can still override them on the command line.
命令行编译器允许你输入相同的命令行参数,它将忽略所有除最后一个之外。这个的话,尽管通过配置文件你可以改变一些设置,你仍然可以覆盖它使用命令行参数。
When dcc32 starts, it looks for DCC32.CFG in the current directory. If the file isn't found there, dcc32 looks in the directory where DCC32.EXE resides.
当dcc32启动时,它查找DCC32.CFG文件在当前目录。如果文件没有找到,dcc32会查找它所在的目录。
Here's an example DCC32.CFG file, defining some default directories for include, object, and unit files, and changing the default states of the $O and $R compiler directives:
以下是一个DCC32.CFG配置文件的例子,定义了关于文件包含、OBJ文件包含、单元文件搜索路径信息,并改变了编译器指令$O和$R的默认值。
-IC:\DELPHI\INC;C:\DELPHI\SRC
-OC:\DELPHI\ASM
-UC:\DELPHI\UNITS
-$R+
-$O-
Now, if you type:
现在,如果你输入:
dcc32 MYSTUFF
the compiler performs as if you had typed the following:
编译器把它当作你输入如下命令:
dcc32 -IC:\DELPHI\INC;C:\DELPHI\SRC -OC:\DELPHI\ASM -UC:\DELPHI\UNITS -$R+ -$O- MYSTUFF
Debug options
调试选项
The compiler has two sets of command-line options that enable you to generate external debugging information: the map file options and the debug info options.
编译器有两个命令行参数可以生成外部调试信息:MAP文件选项和调试信息选项。
Map file (-G) options
Map文件(-G)选项
The -G option instructs the command-line compiler to generate a .map file that shows the layout of the executable file. Unlike the binary format of executable and .dcu files, a .map file is a legible text file that can be output on a printer or loaded into the editor. The -G option must be followed by the letter S, P, or D to indicate the desired level of information in the .map file. A .MAP file is divided into three sections:
选项-G指示命令行编译器生成一个.map文件来查看一个可执行文件的布局。不同于可二进制的可执行文件和.dcu文件,.map文件是一个可读的文本文件,可以被打印或是其它文本编辑器编辑。选项-G后必须跟字符S、P或D,去决定你想要在.map文件列出的信息。一个.MAP文件被分成三个节:
Segment
Publics
Line Numbers
-GS outputs only the Segment section, -GP outputs the Segment and Publics section, and -GD outputs all three sections. -GD also generates a .DRC file that contains tables of all string constants declared using the resourcestring keyword.
-GS选项只输出Segment Section,-GS选项输出Segment和Publics,-GD输出所有的三个Sections.-GD选项也生成一个扩展名为.DRC的文件包含所有的用resourcestring关键字声明的字符串常量。
For moles (program and units) compiled in the {$D+,L+} state (the default), the Publics section shows all global variables, proceres, and functions, and the Line Numbers section shows line numbers for all proceres and functions in the mole. In the {$D+,L-} state, only symbols defined in a unit's interface part are listed in the Publics section. For moles compiled in the {$D-} state, there are no entries in the Line Numbers section.
用默认的编译选项{$D+,L+}编译模块(程序或单元),Publics Section列举所有的全局变量、过程和函数,Line Numbers Section列举模块中所有的过程和函数的行号。如果用{$D+,L-}编译选项编译模块,Publics Section中仅列举在单元的interface部分定义的符号。如果用{$D-}选项编译模块,在Line Numbers Section没有任何入口。
Debug info (-V) options
调度选项(-V)
The -V options (-V, -VN. and -VR), which cause the compiler to generate debug information, can be combined on the command line.
选项-V、-VN、-VR会指示编译器生成调试信息,它们能在命令行中组合使用。
Generate Turbo Debugger debug info (-V) option
生成Turbo Debugger使用的调试信息的选项(-V)
When you specify the -V option on the command line, the compiler appends Turbo Debugger 5.0-compatible external debug information at the end of the executable file. Turbo Debugger includes both source- and machine-level debugging and powerful breakpoints.
当你在命令行中使用-V选项时,编译器会在可执行文件的末尾附加与Turbo Debugger5.0一致的外部调试信息。Turbo Debugger包含代码和硬件级别的强大的断点。
Even though the debug information generated by -V makes the resulting executable file larger, it does not affect the actual code in the executable, and does not require additional memory to run the program.
虽然附加调试信息到查执行文件中会使可执行文件增大,但是它并不影响实际可执行文件中的可执行代码,也不需要额外的内存来启动程序。
The extent of debug information appended to the executable file depends on the setting of the $D and $L compiler directives in each of the moles (program and units) that make up the application. For moles compiled in the {$D+,L+} state, which is the default, all constant, variable, type, procere, and function symbols are known to the debugger. In the {$D+,L-} state, only symbols defined in a unit's interface section are known to the debugger. In the {$D-} state, no line-number records are generated, so the debugger cannot display source lines whe
⑶ 如何定制android源码的编译选项
现仅就工作遇到的问题做个总结。所用硬件平台为amlogic stvm3。---------------------------------------------------------------------------关于版本号:文件build/core/version_defaults.mk用来检查一些跟版本相关的变量是否定义;如果未定义,则使用默认值。这些变量包括 PLATFORM_VERSION # 如 2.2.5 PLATFORM_SDK_VERSION # 8, 对应2.2.5 PLATFORM_VERSION_CODENAME # REL,即发行版 DEFAULT_APP_TARGET_SDK # 同SDK_VERSION或VERSION_CODENAME BUILD_ID # 默认为UNKNOWN BUILD_NUMBER # 默认eng.$(USER).$(shell date +%Y%m%d.%H%M%S)的形式。 version_defaults.mk首先包含进build_id.mk。用户应当配置build_id.mk,而不应该改动version_defaults.mk文件。然后检查上述变量,如未定义则赋值默认值。---------------------------------------------------------------------------关于调试功能(adb)的开启编译android源码之前总是要先运行build/envsetup.sh,以初始化一些常用命令(实际上是bash的函数,如add_lunch_combo)。其中也从以下文件中引入了一些编译设置: device/${CHIPSET_VENDOR}/vendorsetup.sh我们这里使用的CHIPSET_VENDOR为amlogic。比如我们有文件device/amlogic/vendorsetup.sh,内容为"产品名-编译类型(flavor)"列表(称为combo),如下: add_lunch_combo m1ref-eng add_lunch_combo m1ref-user add_lunch_combo m2ref-eng add_lunch_combo m2ref-user add_lunch_combo stvm3-eng add_lunch_combo stvm3-user其中,m1ref和stvm3是产品名(作前缀),后面为编译类型。除此前缀外可选的combo值有: eng, user, userdebug, tests。(参考文件build/core/main.mk中对于变量TARGET_BUILD_VARIANT的筛查条件)我们可以修改vendorsetup.sh文件,来改变为特定设备编译的结果。以下是各个编译类型的特点: eng: 工程模式,用于平台级的调试,是默认的编译类型。
⑷ 如何定制android源码的编译选项 amp;后期安装
文件build/core/version_defaults.mk用来检查一些跟版本相关的变量是否定义;如果未定义,则使用默认值。
这些变量包括
PLATFORM_VERSION # 如 2.2.5
PLATFORM_SDK_VERSION # 8, 对应2.2.5
PLATFORM_VERSION_CODENAME # REL,即发行版
DEFAULT_APP_TARGET_SDK # 同SDK_VERSION或VERSION_CODENAME
BUILD_ID # 默认为UNKNOWN
BUILD_NUMBER # 默认eng.$(USER).$(shell date +%Y%m%d.%H%M%S)的形式。
version_defaults.mk首先包含进build_id.mk。用户应当配置build_id.mk,而不应该改动version_defaults.mk文件。然后检查上述变量,如未定义则赋值默认值。
---------------------------------------------------------------------------
关于调试功能(adb)的开启
编译android源码之前总是要先运行build/envsetup.sh,以初始化一些常用命令(实际上是bash的函数,如add_lunch_combo)。
其中也从以下文件中引入了一些编译设置:
device/${CHIPSET_VENDOR}/vendorsetup.sh
我们这里使用的CHIPSET_VENDOR为amlogic。
比如我们有文件device/amlogic/vendorsetup.sh,内容为"产品名-编译类型(flavor)"列表(称为combo),如下:
add_lunch_combo m1ref-eng
add_lunch_combo m1ref-user
add_lunch_combo m2ref-eng
add_lunch_combo m2ref-user
add_lunch_combo stvm3-eng
add_lunch_combo stvm3-user
其中,m1ref和stvm3是产品名(作前缀),后面为编译类型。
除此前缀外可选的combo值有: eng, user, userdebug, tests。
(参考文件build/core/main.mk中对于变量TARGET_BUILD_VARIANT的筛查条件)
我们可以修改vendorsetup.sh文件,来改变为特定设备编译的结果。
以下是各个编译类型的特点:
eng: 工程模式,用于平台级的调试,是默认的编译类型。
待安装的模块tag有: eng, debug, user, development.
安装不带tag的非APK模块;
所安装应用由产品定义文件给出;
默认属性: ro.secure=0, ro.deuggable=1, ro.kernel.android.checkjni=1
adbd默认开启,adb以root身份运行。
user: 即最终用户版;
待安装的应用tag有: user
安装不带tag的非APK模块;
所安装应用由产品定义文件给出;
默认属性有ro.secure=1, ro.debuggable=0;
默认关闭adbd服务(但可通过应用settings来打开,且adb以shell身份运行);
userdebug: 与user类似,除了:
支持有限的调试功能;
待安装的应用tag有:debug;
默认属性有ro.secure=1, ro.debuggable=1;
默认打开adbd服务,adb以shell身份运行;
例如,由文件build/core/main.mk可以看出,当使用含有userdebug的combo值时,此文件中的临时变量enable_target_debugging会保持为true,相应地,编译过程会执行:
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
这意味着目标系统中根目录下的文件/default.prop文件(对应变量 INSTALLED_DEFAULT_PROP_TARGET )会含有以下行(参考文件build/core/Makefile):
persist.service.adb.enable=1
由此,目标系统会默认开启adbd服务,你就可以通过其它PC来连接目标系统了。
所以,如要默认开启adbd服务,可在设备(如stvm3)定制文件device/amlogic/vendorsetup.sh中增加以下行:
add_lunch_combo stvm3-userdebug
这样在执行bash的lunch函数时,选择此combo就可以默认打开adbd服务(adb以shell身份运行)。
但是,即使adbd已经开启,你仍可能无法通过网络连接到Android进行调试,这涉及到Android的二个属性:
service.adb.tcp.port (优先级高)
persist.adb.tcp.port (优先级低)
注:可查看源码文件system/core/adb/adb.c。
默认地,这两个属性值是5555。有两种方法来设置此变量:
1)(永久性改变)在Android配置文件/init.rc或/init.$MANUFACTUROR.rc中添加一行:
setprop service.adb.tcp.port 5555
2)(临时性改变)在命令行上(你可能需要先通过串口开一个终端)执行如下命令:
setprop service.adb.tcp.port 5555
检查adbd是否支持通过网络链接Android:执行命令
netstat -l -n | grep ":5555"
如果有LISTEN状态的输出,则表示adbd支持网络模式 :) 。
⑸ ubuntu系统下怎么编译内核文件
一、下载源代码和编译软件的准备
安装有关编译程序。安装make ,gcc, make-kpkg,运行menuconfig等等和编译内核相关的工具。安装不了,请检查/etc/apt/sources.list 文件。有关命令:代码:$sudo apt-get install build-essential kernel-package libncurses5-dev
二、解压源代码注意,网上很多教程上说应该解压到 /usr/src,纯属以讹传讹,linux掌门人linus说解压到任何目录上都可以。当然,linus的说法是正确的。我放在自己的主目录下的src目录。如果你下载源代码是放到自己的主目录下或者运行上面的wget下载的,那么运行下列命令:代码:$ cd ~$ mkdir src && tar jfx linux-2.6.25.10.tar.bz2 -C src/现在,源代码就在 ~/src/linux-2.6.25.10进入源代码的目录,准备下一步的工作。后面都在这个目录里面进行。代码:$ cd ~/src/linux-2.6.25.10
三、开始编译前的准备工作。首先,清理以前编译时留下的临时文件。如果是刚刚解开的包,不需要执行这步。如果是第二次或者是第n次编译,那么一定要执行。相关命令如下:代码:$ sudo make mrproper网上很多教程上说把现在使用的内核的config拷贝过来参考,据实验,是不需要的,ubuntu还有debian会自动做这步。不过这条命令倒是可以学习一下。当然你可以将以前的配置拷贝过来。命令:代码:cp /boot/config-`uname -r` ./.config
四、开始配置内核选项。相关命令:代码:$sudo make menuconfig配置用到的键只有几个,esc退出菜单;空格改变选项状态;光标键上下左右移动,回车选定。选项意义:M是编译成可以随时加入的模块,*是编译进入内核,空就是不要。配置选项非常多,具体配置可以参考金步国先生翻译的资料:Linux 2.6.19.x 内核编译配置选项。 请大家遵循一个原则,如果你自己使用的内核已经选用了某个选项,如果你没用充分的理由,不要随便改动。这样虽然内核不那么精简,但是不容易出现问题。我们可以精简的部分是硬件模块部分,对于自己没有的硬件要毫不犹豫的清除。如果你很执着,或者你有洁癖,你也可以一项项对过去,按照金步国先生的资料描述去选择基本上没有问题。
五、必须强调的几个选项:1、
在“General setup”里面的“Prompt for development and/or incomplete
code/drivers”金步国认为是不需要。但是如果你的硬件比较新,那几乎是必须选的,这样,我们才可以找到4965无线网卡,alsa声音驱动等
等。Kernel log buffer size 我选15,双核。如果你用ia64,要选16。Control Group support 集群支持?可以不要Choose SLAB allocator (SLUB (Unqueued Allocator)) 内存管理模式slab和slub选择slub。
2、在“Block layer”里,假如没有2TB的硬盘,就去掉:Support for Large Block Devices 。Support for Large Single Files 也不需要,谁有2TB的文件?
3、Processor type and features中是关于cpu的,要认真选。Symmetric multi-processing support是打开多核的开关,我的cpu是双核的,选中。Processor family (Core 2/newer Xeon) 我的是Core 2/newer Xeon。找到自己的cpu后,把Generic x86 support选项取消。Subarchitecture Type 选(PC-compatible)Maximum number of CPUs 输入自己的核心数目,我输入2。SMT (Hyperthreading) scheler support说的是超线程技术,P4有支持的,我的t8100不支持,目前大部分市场上的家用cpu都不支持。High Memory Support (4GB) 1G以下选1G;我是3G,选4G;4G以上的选16G在“ Timer frequency ”里,默认是250Hz,较新的cpu都可以选择了1000Hz,性能更好。
4、Power management options中把APM (Advanced Power Management) BIOS support关闭。现在的电脑都用acpi了。CPU Frequency scaling 是笔记本cpu节电技术Default CPUFreq governor (conservative) cpu节电模式有四个,笔记本默认选conservative比较好。ACPI Processor P-States driver 必须选,不然CPU Frequency就不能用。后面的可选自己硬件相关的,我选的是Intel Enhanced SpeedStep和 Intel Speedstep on ICH-M chipsets,其他的统统消灭。
5、Bus options的选择:Bus options (PCI, PCMCIA, EISA, MCA, ISA)PCI support PCI Express support 现在新买的机器基本上都是PCI Express了ISA support 较新的新机器没有ISA设备,可以去掉MCA support 去掉NatSemi SCx200 support 去掉PCI Hotplug Support Support for PCI Hotplug (EXPERIMENTAL) 如果没有PCI热插拔设备,去掉这里的选项可以考虑全部编译进内核,而不是以模块形式存在。
6、Device Drivers是重点,由于linux不但面向个人工作站,更多的是面向服务器的应用,所以可以把自己机器上没有的硬件全部去掉,而不用面面俱到。但是通用型的选项要慎重。比如在网卡的部分,除了我的千兆网卡 Broadcom Tigon3 support和4965无线网卡Intel Wireless WiFi 4965AGN,其余的硬件支持统统去掉。再比如声卡部分,我的是hd声卡,我只是在PCI devices中,选intel hd 声卡,再选Build IDT/Sigmatel HD-audio codec support,除此之外的硬件支持全部去掉。
声卡还有一个细节,在ubuntu7.10里面, 需要在/etc/modprobe.d/alsa-base后面添加options
snd-hda-intel probe_mask=1
model=3stack,这样我的笔记本喇叭才可以发声,不然只有外接耳机或者音箱。这次编译以后,这个动作就不必了,但是两个耳机插口只有一个可以用
了。再比如我的电脑中没有agp,就可以直接把agp相关的选项全部取消。要注意的:ATA/ATAPI/MFM/RLL support Include IDE/ATA-2 DISK support 如果你的/boot是放在IDE硬盘上,那么这里一定要选*,选M都不行。否则启动时会出现“waiting for root file system”的提示而停滞不前。 SCSI emulation support 要用刻录机,必须选。SCSI device support 现在都是SATA硬盘,一定要选* SCSI disk support 如果你的/boot放在SATA硬盘上,一定要选*。
SCSI CDROM support 虽然康宝刻录机是ide接口的,但是必须把它当成scsi接口的,这是老问题了。用刻录机,必须选。
Graphics supportSupport for frame buffer devices 选中,进入选择 VESA VGA graphics support 选上,不然字符界面启动会有问题,后面的显卡选择:由于我的显卡是nvidia 8400gs,要自己安装nvidia公司的驱动,所以一个都没有选。这样导致ubuntu开机动画会出问题,我索性在grub中的splash字符全部删除,把开机动画关闭。字符界面很正常。 Console display driver support 有人开机后字符控制台错误,就是这部分选项没有选,出问题了。 Framebuffer Console support 需要打开。
Bootup logo 开机图标,会在自检的画面上加上个性图标。需要在grub上添加“vga=”的选项 简称fuse。是必选的,如果你要用windows分区。
CD-ROM/DVD Filesystems ISO 9660 CDROM file system support 一般选*DOS/FAT/NT Filesystems VFAT (Windows-95) fs support 有FAT32分区就选*吧 NTFS file system support 有NTFS分区就选*吧 NTFS write support 如果想对 NTFS分区进行写操作,选*必须将启动盘的文件系统编译进内核,默认是编译成模块,这样无法启动系统。ubuntu采用的文件系统是ext3,请把ext2,ext3相关的必要选项都编译进入内核。
8、Virtualization这个大类是我多花几百元买t8100的主要原因,因为t8100支持intel vt技术使linux上的虚拟机的性能大幅度提高。这里的选项我除了amd的,其他都编译成模块。
9、全部设置完成,最后一项是保存设置。按照我的习惯,先在上一层目录保存一个备份,文件名类似 ../config20080630然后再保存到当起目录,文件名 .config退出设置程序。
六、开始编译内核。ubuntu的工具是make-kpkg,和其他的发行版相比,步骤相对简单。相关命令:代码:$sudo make-kpkg clean 这条命令好像不要超级权限,很多资料上说要,不过这不是原则问题。
$ sudo make-kpkg -initrd --initrd --append-to-version=dell1400 kernel_image kernel-headers上述命令中的dell1400可以用自己喜欢的字符代替,最后的字符一定是数字.输完上述命令回车之前,建议大家把浏览器还有别的运用程序都关掉,机器开始的工作比较艰苦。
我的机器大概十几分钟。
七、安装内核编译完成就是安装工作。编译好的内核在上一层目录。包括linux-headers-...-_i386.deb和linux-image-...-i386.deb两个文件,如果你不搞开发的话,只要安装内核就可以,头文件以后要用的时候再说。安装相关命令:
代码:$ cd ..$ sudo dpkg -i linux-image-(按tab键)文件名很长,如果不用tab自动补足是不可能的,tab键万岁。安装完成后和老内核比较一下大小代码:
$ ls -l /boot/
八、重新启动验证新内核。代码:$ sudo reboot
九、显卡驱动如果你的显卡和我一样是nvidia显卡,启动之后往往无法正常进入x-window。即使能看到gdm登录界面,效果也是很差的。那么就要安装nvidia驱动。用ctrl+alt+f1 进入字符命令行,输入用户名,密码登录。 #ps ax看看和gdm相关的进程,把这些进程全部关闭;用sudo /etc/init.d/gdm stop有可能有一个进程没有关闭:#kill 进程号然后安装nvidia显卡驱动,当然驱动要先下好,到nvidia驱动所在的目录里,运行:# sh ./NVIDIA-Linux-x86-173.14.12-pkg1.run重新启动以后就ok。要用nvidia的驱动,每次升级内核都要这么做。
十、无线网卡相关的内核选项是Networking --->Wireless --->Generic IEEE 802.11 Networking Stack (mac80211)还有4965的驱动。4965
无线网卡驱动虽然已经编入内核,但没有firmware无法使用。需要把原来内核的firmware拷贝到新内核对应的目录,名字和内核一致,我的内核是
linux-image-2.6.25.10dell1400,那建的目录名就是2.6.25.10dell1400。代码:具体命令:$ cd /lib/firmware/$ sudo mkdir 2.6.25.10dell1400把你的老内核中的4965的firmware拷贝过来。$ sudo cp 2.6.24-16-generic/* 2.6.25.10dell1400/上面的命令和下面的命令是等价的:$ cd /lib/firmware/$ sudo cp -R 2.6.24-16-generic/ 2.6.25.10dell1400/
重新启动系统,无线网卡就正常了。
附编译使用的机器配置:dell vostro 1400,t8100,nvidia 8400cs显卡,内置SigmaTel STAC9228芯片的声卡,4965无线网卡,BCM5906M千兆网卡,3G内存,160G硬盘,combo刻录。
编译系统版本:ubuntu 8.04桌面版.
⑹ cmake中修改默认编译器的两个问题
在为交叉编译工程写cmake脚本时,可以在脚本里修改默认编译器的值。这种方法会碰到下面两个问题
例如,下面是一个经过简化后的CMakeLists.txt:
cmake+make的输出如下:
可以看到,set(CMAKE_CXX_COMPILER "/usr/bin/g++-4.8")命令之后,默认编译器已经由g++-5.5修改为了g++-4.8,且编译阶段确实也使用的是g++-4.8。但是此时CMAKE_CXX_COMPILER_VERSION的值仍然是5.5。
例如,顶层CMakeLists.txt中的内容如下:
子目录sub/CMakeLists.txt中只有一行:
cmake就会陷入死循环:
问题1:
问题2:
但是有个更简单的方法,可以解决以上所有问题:
在第一个project命令前,修改默认编译器的定义。
例如:
⑺ Linux 编译选项
gcc -E source_file.c
-E,只执行到预编译。直接输出预编译结果。gcc -S source_file.c
-S,只执行到源代码到汇编代码的转换,输出汇编代码。gcc -c source_file.c
-c,只执行到编译,输出目标文件。gcc (-E/S/c/) source_file.c -o output_filename
-o, 指定输出文件名,可以配合以上三种标签使用。
-o 参数可以被省略。这种情况下编译器将使用以下默认名称输出:
-E:预编译结果将被输出到标准输出端口(通常是显示器)
-S:生成名为source_file.s的汇编代码
-c:生成名为source_file.o的目标文件。
无标签情况:生成名为a.out的可执行文件。gcc -g source_file.c
-g,生成供调试用的可执行文件,可以在gdb中运行。由于文件中包含了调试信息因此运行效率很低,且文件也大不少。
这里可以用strip命令重新将文件中debug信息删除。这是会发现生成的文件甚至比正常编译的输出更小了,这是因为strip把原先正常编译中的一些额外信息(如函数名之类)也删除了。用法为 strip a.outgcc -s source_file.c
-s, 直接生成与运用strip同样效果的可执行文件(删除了所有符号信息)。gcc -O source_file.c
-O(大写的字母O),编译器对代码进行自动优化编译,输出效率更高的可执行文件。
-O 后面还可以跟上数字指定优化级别,如:
gcc -O2 source_file.c
数字越大,越加优化。但是通常情况下,自动的东西都不是太聪明,太大的优化级别可能会使生成的文件产生一系列的bug。一般可选择2;3会有一定风险。gcc -Wall source_file.c
-W,在编译中开启一些额外的警告(warning)信息。-Wall,将所有的警告信息全开。gcc source_file.c -L/path/to/lib -lxxx -I/path/to/include
-l, 指定所使用到的函数库,本例中链接器会尝试链接名为libxxx.a的函数库。
-L,指定函数库所在的文件夹,本例中链接器会尝试搜索/path/to/lib文件夹。
-I, 指定头文件所在的文件夹,本例中预编译器会尝试搜索/path/to/include文件夹。
⑻ Unity3D怎么更改默认编译器版本
首先我们要打开Unity,找到菜单栏的Edit(编辑栏)里面的Preferences(偏好设置)
打开Preferences以后我们找到Unity面板中的External Tools(外部工具/插件)面板,那么在这里打开就可以修改或者设置一些内容,比如VS编译器版本 安卓SDK等内容!!
那么咱们找到Extemal Script Editor(Extemal脚本编辑器,也就是所用的visual studio的版本)选项,咱们的编译器版本就是在这里进行选择啦~~~
点击右方的Visual Studio 2012位置就可以进行VS编译器版本内容的切换啦!从这之后大家就不用担心更换版本好药附带安装VS。
希望可以帮助到你 想要下载 unity3d插件 可以到纳金网论坛去下载
