C/C++ 程序的build过程

(This article is under constant construction)
DISCLAIMER: 本文的主要内容来自https://gcc.gnu.org/onlinedocs/gcc/


这篇随笔主要记录有关build C/C++程序的知识. 包括

  • gcc/g++ 的各个参数的含义
  • 编译, 链接等概念
  • Linux中make的使用
  • 静态/动态链接库
  • Linux的文件系统

从源文件到可执行文件

Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. GCC is capable of preprocessing and compiling several (source) files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file.

  1. source file(s): preprocessing, compilation proper
  2. assembler input file(s): assembly
  3. object file(s): linking
  4. executable file

gcc/g++ 编译选项 (options) 的含义

-c
Compile or (should be "and"?) assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file.

By default, the object file name for a source file is made by replacing the suffix ‘.c’, ‘.i’, ‘.s’, etc., with ‘.o’.

Unrecognized input files, not requiring compilation or assembly, are ignored.

-S
Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified.

By default, the assembler file name for a source file is made by replacing the suffix ‘.c’, ‘.i’, etc., with ‘.s’.

Input files that don't require compilation are ignored.

-E
Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.

Input files that don't require preprocessing are ignored.

-o file
Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.

Options for Linking

These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler is not doing a link step.

object-file-name
A file name that does not end in a special recognized suffix is considered to name an object file or library. (Object files are distinguished from libraries by the linker according to the file contents.) If linking is done, these object files are used as input to the linker.

-c
-S
-E

If any of these options is used, then the linker is not run, and object file names should not be used as arguments.

-llibrary

Search the library named library when linking.

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

The linker searches a standard list of directories (details?) for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.

关于 LD_LIBRARY_PATH 的链接

转载于:https://www.cnblogs.com/Patt/p/6020399.html

Borland C++ Builder 6 (汉化补丁终结版) 汉化说明 ======================================================= 欢迎使用剑客软件,您的支持是我们前进的不懈动力。 ------------------------------------------------------------------------- 软件名称: Borland C++ Builder 6.0 (汉化补丁终结版) 软件版本: 6.0 (Build 10.166 , Update 4) 授权形式: 免费 作品类型: 汉化补丁 应用平台: Win9x/Me/NT/2000/XP/2003 软件作者: 辛玉强 作者主页: Http://swordxy.126.com 作者邮件: xy_0717@163.com ------------------------------------------------------------------------- 软件简介: Borland C++ Builder 是目前唯一完美集成 COBRA 与 COM/COM+ 的 C++ 集成开发环境,可以快速开发具有 Web 服务支持功能的电子商务应用程序,全球率先实现跨平台、高效可视化开发 Windows/Linux 应用程序,兼容 CLX、VCL 和 Borland C++ for Linux,增强了对于 Microsoft Visual C++程序的兼容程度,提供 MFC 6.0 版与 ATL 3.0 版函数库,比起 Visual C++ 的 MFC 来,VCL 要先进得多。 ------------------------------------------------------------------------- 新增功能: 在 Borland C++Builder 6 汉化补丁增强版 的基础上,进一步修正了 Borland 的图片及资源编辑器、SQL 监视器的一些小的翻译问题,力争翻译的更贴切。同时, 增加了对 Borland SQL 浏览器 、桌面数据库 、BDE 管理员 的汉化支持。 让您的 C++ Builder 更符合国人的习惯。 另外又新增加了安装时自选组件的功能, 您可以根据自己的需要来决定哪些组件需要汉化,定制属于您自己的开发环境。 最后,加入了一些其他的文件关联方式,如: C 、HPP 、DCR 、RES 、PAS 等等,便于您直接拿记事本来修改 C++ 的源文件而不用开启 C++Builder ,对于小范围的修改代码比较方便。 ------------------------------------------------------------------------- 汉化方法: 汉化前请确认 C++ Builder 6.0 及其相关程序程序没有运行,否则强行汉化可能会损坏文件。 下载后解压缩 RAR,运行 BCBswordH6.exe 将文件安装到原英文 BCB.exe 所在的目录 (一般为: C:\Program Files\Borland\CBuilder6\Bin) 即可使用。 如果您希望以后还能继续使用英文版, 请注意选择备份旧的文件,并注意在卸载本汉化补丁时选择 "反转" 以恢复英文版 (如果您不创建文件备份,卸载本汉化补丁时将不能恢复英文版,并且您需要重新安装 Borland C++ Builder 6.0 以恢复英文版)。 ------------------------------------------------------------------------- 郑重声明:  1.此软件原始版本版权归 Borland 公司所有,本人仅在原始软件基础上进行简体中文本地化。  2.感谢您使用 swordxy 的汉化作品。本人所有汉化作品均为免费发放,任何组织或个人未经本人允许,不得将本人的汉化作品用于商业活动或任何其它赢利性活动中。  3.本人的汉化只为使用方便而做,使用 swordxy 的汉化作品是您的自由选择,本人并不对由此给您的计算机系统带来的任何问题负责。  4.欢迎转载、传播 swordxy 的所有汉化作品。但请注意在转载或传播过程中保持汉化文件的完整性。请勿删除此说明文件并请尽量少改动汉化文件名。如果直接链接本站下载链接,请在下载位置注明出处。  5.在使用过程中如果发现翻译错误之处请及时来信指出。 6.如果确系因使用本软件导致软件运行不正常或系统不稳定(请先确认该问题是否原版软件已经存在), swordxy 并不能提供任何补偿或补救措施,swordxy 只能在纯学术研究的前提下,在获知具体出错现象后,尽可能的给与私人的友情帮助。 7.请勿向 swordxy 询问任何软件注册破解问题,对此类问题本人概不答复,软件使用中如有任何疑问,请发邮件到 xy_0717@163.com,但本人不保证一定能够解答。 -------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值