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插件 可以到納金網論壇去下載
