导航:首页 > 源码编译 > so命令行编译

so命令行编译

发布时间:2022-12-31 09:31:10

A. 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

B. 什么是SO文件

SO文件是linux下共享库文件,它的文件格式被称为ELF文件格式。由于android操作系统的底层基于Linux系统,所以SO文件可以运行在Android平台上。

Android系统也同样开放了C/C++接口供开发者开发Native程序。由于基于虚拟机的编程语言java更容易被人反编译,因此越来越多的应用将其中的核心代码以C/C++为编程语言,并且以SO文件的形式供上层JAVA代码调用,以保证安全性。

(2)so命令行编译扩展阅读:

so文件使用方法:

(1)动态库的编译。这里有一个头文件:so_test.h,三个.c文件:test_a.c、test_b.c、test_c.c,我们将这几个文件编译成一个动态库:libtest.so。

命令:$ gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so不用该标志外部程序无法连接。相当于一个可执行文件。

(2)动态库的链接这里有个程序源文件 test.c 与动态库 libtest.so 链接生成执行文件 test:命令:$ gcc test.c -L. -ltest -o test命令:$ ldd test执行test,可以看到它是如何调用动态库中的函数的。

参考资料来源:网络—SO(软件编程)

C. android开发,怎么使用ndk编译成.so文件

一、首先下载android-ndk,官方网站是:http://developer.android.com/tools/sdk/ndk/index.html
目前最新的版本是android-ndk-r8e-windows-x86.zip,下载地址:
http://dl.google.com/android/ndk/android-ndk-r8e-windows-x86.zip
下载后把压缩解压出来,例如:D:\ndk,目录下的ndk-build.cmd就是用来编译的批处理命令。
二、编译,打开cmd命令行窗口,cd进入目录:D:\ndk\samples\hello-jni,
然后执行命令:D:\ndk\ndk-build.cmd(如果设置过环境变量则直接使用ndk-build.cmd)来编译hello-jni,如果没有错误会输出:
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
"Compile thumb : hello-jni <= hello-jni.c
SharedLibrary : libhello-jni.so
Install : libhello-jni.so => libs/armeabi/libhello-jni.so
三、创建android应用程序并使用so文件
打开eclipse创建一个android应用程序HelloJni,默认的com.example.hellojni包下面有一个MainActivity.java,
在此包下添加一个HelloJni.java,

D. Linux下用交叉编译器编译报错缺少Libc.so.6【求教】

#打开/etc/ld.so.conf,在最后一行添加/home/xassassin/armlinuxdev/bin/lib/
$sudovim/etc/ld.so.conf
#执行此命令,然后再编译
$sudoldconfig

E. linux中如何用命令行运行一个so文件

*.so 吗? 是linux的动态链接库文件,不能运行,是给其它程序调用的函数库。

F. 关于Linux中的so文件

你知道windows下的dll文件吗???
其实和linux下的so文件是一回事,,so文件也是编译好了的二进制的链接库文件,,,
一般来说都是c或c++编译出来的,,java的话通常是用的字节码,也就是class文件。。
你自己写一个 helloworld的c程序,然后在命令行下用编译器编译gcc -c helloworld.c -o hello.o这样编译出来的结果就是那样的东西了。。这样的文件是不能直接运行的。。

G. 请教关于android linux动态库.so的加载调用

1、 .so动态库的生成
可使用gcc或者g++编译器生成动态库文件(此处以g++编译器为例)
g++ -shared -fPIC -c XXX.cpp
g++ -shared -fPIC -o XXX.so XXX.o
2、 .so动态库的动态调用接口函数说明
动态库的调用关系可以在需要调用动态库的程序编译时,通过g++的-L和-l命令来指定。例如:程序test启动时需要加载目录/root/src/lib中的libtest_so1.so动态库,编译命令可照如下编写执行:
g++ -g -o test test.cpp –L/root/src/lib –ltest_so1
(此处,我们重点讲解动态库的动态调用的方法,关于静态的通过g++编译命令调用的方式不作详细讲解,具体相关内容可上网查询)

Linux下,提供专门的一组API用于完成打开动态库,查找符号,处理出错,关闭动态库等功能。
下面对这些接口函数逐一介绍(调用这些接口时,需引用头文件#include <dlfcn.h>):
1) dlopen
函数原型:void *dlopen(const char *libname,int flag);
功能描述:dlopen必须在dlerror,dlsym和dlclose之前调用,表示要将库装载到内存,准备使用。如果要装载的库依赖于其它库,必须首先装载依赖库。如果dlopen操作失败,返回NULL值;如果库已经被装载过,则dlopen会返回同样的句柄。
参数中的libname一般是库的全路径,这样dlopen会直接装载该文件;如果只是指定了库名称,在dlopen会按照下面的机制去搜寻:
a.根据环境变量LD_LIBRARY_PATH查找
b.根据/etc/ld.so.cache查找
c.查找依次在/lib和/usr/lib目录查找。
flag参数表示处理未定义函数的方式,可以使用RTLD_LAZY或RTLD_NOW。RTLD_LAZY表示暂时不去处理未定义函数,先把库装载到内存,等用到没定义的函数再说;RTLD_NOW表示马上检查是否存在未定义的函数,若存在,则dlopen以失败告终。
2) dlerror
函数原型:char *dlerror(void);
功能描述:dlerror可以获得最近一次dlopen,dlsym或dlclose操作的错误信息,返回NULL表示无错误。dlerror在返回错误信息的同时,也会清除错误信息。
3) dlsym
函数原型:void *dlsym(void *handle,const char *symbol);
功能描述:在dlopen之后,库被装载到内存。dlsym可以获得指定函数(symbol)在内存中的位置(指针)。如果找不到指定函数,则dlsym会返回NULL值。但判断函数是否存在最好的方法是使用dlerror函数,
4) dlclose
函数原型:int dlclose(void *);
功能描述:将已经装载的库句柄减一,如果句柄减至零,则该库会被卸载。如果存在析构函数,则在dlclose之后,析构函数会被调用。
3、 普通函数的调用
此处以源码实例说明。各源码文件关系如下:
test_so1.h和test_so1.cpp生成test_so1.so动态库。
test_so2.h和test_so2.cpp生成test_so2.so动态库。
test_dl.cpp生成test_dl可执行程序,test_dl通过dlopen系列等API函数,并使用函数指针以到达动态调用不同so库中test函数的目的。

H. 求助vxwork编译命令行编译错误

Makefile

一个工程中的源文件不计数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。

makefile带来的好处就是——“自动化编译”,一旦写好,只需要一个make命令,整个工程完全自动编译,极大的提高了软件开发的效率。make是一个命令工具,是一个解释makefile中指令的命令工具,一般来说,大多数的IDE都有这个命令,比如:Delphi的make,Visual C++的nmake,Linux下GNU的make。可见,makefile都成为了一种在工程方面的编译方法。

Make工具最主要也是最基本的功能就是通过makefile文件来描述源程序之间的相互关系并自动维护编译工作。而makefile 文件需要按照某种语法进行编写,文件中需要说明如何编译各个源文件并连接生成可执行文件,并要求定义源文件之间的依赖关系。makefile 文件是许多编译器--包括 Windows NT 下的编译器--维护编译信息的常用方法,只是在集成开发环境中,用户通过友好的界面修改 makefile 文件而已。

在 UNIX 系统中,习惯使用 Makefile 作为 makfile 文件。如果要使用其他文件作为 makefile,则可利用类似下面的 make 命令选项指定 makefile 文件:

$ make -f Makefile.debug

例如,一个名为prog的程序由三个C源文件filea.c、fileb.c和filec.c以及库文件LS编译生成,这三个文件还分别包含自己的头文件a.h 、b.h和c.h。通常情况下,C编译器将会输出三个目标文件filea.o、fileb.o和filec.o。假设filea.c和fileb.c都要声明用到一个名为defs的文件,但filec.c不用。即在filea.c和fileb.c里都有这样的声明:

#include "defs"

那么下面的文档就描述了这些文件之间的相互联系:

---------------------------------------------------------

#It is a example for describing makefile

prog : filea.o fileb.o filec.o
cc filea.o fileb.o filec.o -LS -o prog
filea.o : filea.c a.h defs
cc -c filea.c
fileb.o : fileb.c b.h defs
cc -c fileb.c
filec.o : filec.c c.h
cc -c filec.c

----------------------------------------------------------

这个描述文档就是一个简单的makefile文件。

从上面的例子注意到,第一个字符为 # 的行为注释行。第一个非注释行指定prog由三个目标文件filea.o、fileb.o和filec.o链接生成。第三行描述了如何从prog所依赖的文件建立可执行文件。接下来的4、6、8行分别指定三个目标文件,以及它们所依赖的.c和.h文件以及defs文件。而5、7、9行则指定了如何从目标所依赖的文件建立目标。

当filea.c或a.h文件在编译之后又被修改,则 make 工具可自动重新编译filea.o,如果在前后两次编译之间,filea.C 和a.h 均没有被修改,而且test.o还存在的话,就没有必要重新编译。这种依赖关系在多源文件的程序编译中尤其重要。通过这种依赖关系的定义,make 工具可避免许多不必要的编译工作。当然,利用Shell脚本也可以达到自动编译的效果,但是,Shell 脚本将全部编译任何源文件,包括哪些不必要重新编译的源文件,而 make 工具则可根据目标上一次编译的时间和目标所依赖的源文件的更新时间而自动判断应当编译哪个源文件。

Makefile文件作为一种描述文档一般需要包含以下内容:

◆ 宏定义
◆ 源文件之间的相互依赖关系
◆ 可执行的命令

Makefile中允许使用简单的宏指代源文件及其相关编译信息,在Linux中也称宏为变量。在引用宏时只需在变量前加$符号,但值得注意的是,如果变量名的长度超过一个字符,在引用时就必须加圆括号()。

下面都是有效的宏引用:

$(CFLAGS)
$Z
$(Z)

其中最后两个引用是完全一致的。

需要注意的是一些宏的预定义变量,在Unix系统中,$*、$@、$?和$<四个特殊宏的值在执行命令的过程中会发生相应的变化,而在GNU make中则定义了更多的预定义变量。关于预定义变量的详细内容,宏定义的使用可以使我们脱离那些冗长乏味的编译选项,为编写makefile文件带来很大的方便。

---------------------------------------------------------

# Define a macro for the object files
OBJECTS= filea.o fileb.o filec.o

# Define a macro for the library file
LIBES= -LS

# use macros rewrite makefile
prog: $(OBJECTS)

cc $(OBJECTS) $(LIBES) -o prog

……

---------------------------------------------------------

此时如果执行不带参数的make命令,将连接三个目标文件和库文件LS;但是如果在make命令后带有新的宏定义:

make "LIBES= -LL -LS"

则命令行后面的宏定义将覆盖makefile文件中的宏定义。若LL也是库文件,此时make命令将连接三个目标文件以及两个库文件LS和LL。

在Unix系统中没有对常量NULL作出明确的定义,因此我们要定义NULL字符串时要使用下述宏定义:

STRINGNAME= //这里有待考证

makefile 中的变量(宏)

GNU 的 make 工具除提供有建立目标的基本功能之外,还有许多便于表达依赖性关系

以及建立目标的命令的特色。其中之一就是变量或宏的定义能力。如果你要以相同的编译

选项同时编译十几个 C 源文件,而为每个目标的编译指定冗长的编译选项的话,将是非

常乏味的。但利用简单的变量定义,可避免这种乏味的工作:

# Define macros for name of compiler
CC = gcc

# Define a macr o for the CC flags
CCFLAGS = -D_DEBUG -g -m486

# A rule for building a object file
test.o: test.c test.h
$(CC) -c $(CCFLAGS) test.c

在上面的例子中,CC 和 CCFLAGS 就是 make 的变量。GNU make 通常称之为变量,

而其他 UNIX 的 make 工具称之为宏,实际是同一个东西。在 makefile 中引用变量的值

时,只需变量名之前添加 $ 符号,如上面的 $(CC) 和 $(CCFLAGS)。

GNU make 有许多预定义的变量,这些变量具有特殊的含义,可在规则中使用。表 13-2

给出了一些主要的预定义变量,除这些变量外,GNU make 还将所有的环境变量作为自己

的预定义变量。

表 13-2 GNU make 的主要预定义变量

预定义变量
含义

$*
不包含扩展名的目标文件名称。
$+
所有的依赖文件,以空格分开,并以出现的先后为序,可能包含重复的依赖文件。
$<
第一个依赖文件的名称。
$?
所有的依赖文件,以空格分开,这些依赖文件的修改日期比目标的创建日期晚。

$@
目标的完整名称。
$^
所有的依赖文件,以空格分开,不包含重复的依赖文件。
$%
如果目标是归档成员,则该变量表示目标的归档成员名称。例如,如果目标名称为
mytarget.so(image.o),则 $@ 为 mytarget.so,而 $% 为 image.o。
AR
归档维护程序的名称,默认值为 ar。
ARFLAGS
归档维护程序的选项。

AS
汇编程序的名称,默认值为 as。
ASFLAGS

汇编程序的选项。
CC
C 编译器的名称,默认值为 cc。

CFLAGS
C 编译器的选项。
CPP
C 预编译器的名称,默认值为 $(CC) -E。
CPPFLAGS
C 预编译的选项。
CXX

C++ 编译器的名称,默认值为 g++。
CXXFLAGS
C++ 编译器的选项。
FC
FORTRAN 编译器的名称,默认值为 f77。
FFLAGS
FORTRAN 编译器的选项。

I. 请问我有一个.so文件,如何在Linux下编程使用呢

-lxx

xx是你的.so文件名

其实使用方法和你使用数学库函数是一样的,源代码中添加

#include <math.h>,编译的时候,加上-lm参数。

注:linux下的.so文件为共享库,相当于windows下的dll文件。

(9)so命令行编译扩展阅读:

linux下编写调用so文件实例

.so是Linux(Unix)下的动态链接库. 和.dll类似.

比如:

文件有: a.c, b.c, c.c

gcc -c a.c

gcc -c b.c

gcc -c c.c

gcc -shared libXXX.so a.o b.o c.o

要使用的话也很简单. 比如编译d.c, 使用到libXXX.so中的函数, libXXX.so地址是MYPATH
gcc d.c -o d -LMYPATH -lXXX

注意不是-llibXXX

test.c文件和一个test.h,这两个文件要生成libsotest.so文件。然后我还有一个testso.c文件,在这个文件里面调用libsotest.so中的函数。

编写的过程中,首先是编译so文件,我没有编写makefile文件,而是参考的2里面说的直接写的gcc命令。

因为so文件里面没有main函数,所以是不可执行的,所以编译的时候要加上-c,只生成目标文件。

阅读全文

与so命令行编译相关的资料

热点内容
程序员战门课 浏览:474
config保存服务器地址 浏览:317
预订网吧座位的app叫什么 浏览:416
香港服务器主机地址 浏览:640
网店美工pdf 浏览:447
一堆文件夹怎么弄出来 浏览:743
博途如何编译硬件 浏览:418
fortran程序pdf 浏览:504
电池消耗算法 浏览:394
服务器中断连接怎么处理 浏览:222
上世纪互联网不发达程序员很难 浏览:841
语音识别android开源 浏览:762
地埋式垃圾压缩中转站 浏览:902
apachehttpdlinux 浏览:944
快递员中通app预付款是什么 浏览:843
java路径转义 浏览:857
keytool加密算法 浏览:131
笑脸图案的APP相机是什么软件 浏览:249
app软件为什么会被下架 浏览:981
从内存到硬盘的命令是 浏览:52