stackoverflow上面关于LINK错误的一个答案

编译一个C++程序依次有哪些的步骤

  1. 物理源文件(代码的真实存储的文件)的字符被映射,通过系统定义的方式进行,映射为基本源字符集(比如换行字符变成结束符)

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary. [SNIP]

  1. 每个反斜杠后面跟一个换行符的实例都会被删除,变成把physical source的行拼接到logical source的行。(不懂)

Each instance of a backslash character () immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. [SNIP]

  1. 源文件被分解为预处理标记和空白字符的句子(包括注释)

The source file is decomposed into preprocessing tokens (2.5) and sequences of white-space characters (including comments). [SNIP]

  1. 预处理指令被执行,宏调用展开,_Pragma一元表达式被执行。

Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed. [SNIP]

  1. 所有被设置成字面值的源文件字符都会被转换成对应的可执行字符。

Each source character set member in a character literal or a string literal, as well as each escape sequence and universal-character-name in a character literal or a non-raw string literal, is converted to the corresponding member of the execution character set; [SNIP]

  1. 相邻的字符串字面值的token是连接在一起的。

Adjacent string literal tokens are concatenated.

  1. 空白字符分隔的token将会失效。每个预处理的token转换成另一种token,这种token是经过语法分析和语义分析产生 的,并且被翻译为一个翻译单元。

White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. (2.7). The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. [SNIP]

  1. 翻译的翻译单元和实例单元会被组合成下面这样:

Translated translation units and instantiation units are combined as follows: [SNIP]

  1. 所有的外部引用的问题都将被解决。相应的没有在当前转换定义的库将会被链接好,所有的转换输出被收集到一个程序映象中,这个映象包含了程序在运行环境运行需要的信息。

All external entity references are resolved. Library components are linked to satisfy external references to entities not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment.

所以出现LINK错误的时候,先要理解在哪个过程发生的,然后根据错误信息去分析。这一段资料看得迷迷糊糊,好多不知道啥意思。

下篇文章会仔细研究一下编译链接的过程。

posted @ 2016-03-07 14:25  arctanx  阅读(233)  评论(0编辑  收藏  举报