什么是未定义的引用/未解决的外部符号错误,如何解决?

本文翻译自:What is an undefined reference/unresolved external symbol error and how do I fix it?

What are undefined reference/unresolved external symbol errors? 什么是未定义的参考/未解决的外部符号错误? What are common causes and how to fix/prevent them? 常见原因是什么?如何解决/预防它们?

Feel free to edit/add your own. 随意编辑/添加自己的。


#1楼

参考:https://stackoom.com/question/ql1U/什么是未定义的引用-未解决的外部符号错误-如何解决


#2楼

Compiling a C++ program takes place in several steps, as specified by 2.2 (credits to Keith Thompson for the reference) : 编译C ++程序分2.2(分给Keith Thompson供参考)指定,分几个步骤进行

The precedence among the syntax rules of translation is specified by the following phases [see footnote] . 翻译的语法规则中的优先级由以下阶段指定[请参见脚注]

  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] [SNIP]
  2. 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] [SNIP]
  3. The source file is decomposed into preprocessing tokens (2.5) and sequences of white-space characters (including comments). 源文件被分解为预处理令牌(2.5)和空白字符序列(包括注释)。 [SNIP] [SNIP]
  4. Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed. 执行预处理指令,扩展宏调用,并执行_Pragma一元运算符表达式。 [SNIP] [SNIP]
  5. 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] [SNIP]
  6. Adjacent string literal tokens are concatenated. 相邻的字符串文字标记是串联在一起的。
  7. White-space characters separating tokens are no longer significant. 分隔标记的空格字符不再重要。 Each preprocessing token is converted into a token. 每个预处理令牌都将转换为令牌。 (2.7). (2.7)。 The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. 对生成的令牌进行语法和语义分析,并将其作为翻译单元进行翻译。 [SNIP] [SNIP]
  8. Translated translation units and instantiation units are combined as follows: [SNIP] 翻译的翻译单元和实例化单元的组合如下: [SNIP]
  9. 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. 所有此类转换器输出都收集到一个程序映像中,该映像包含在其执行环境中执行所需的信息。 (emphasis mine) (强调我的)

[footnote] Implementations must behave as if these separate phases occur, although in practice different phases might be folded together. [脚注]尽管实际上不同的阶段可能会折叠在一起,但实现方式必须表现得好像这些单独的阶段一样。

The specified errors occur during this last stage of compilation, most commonly referred to as linking. 指定的错误发生在编译的最后阶段,通常称为链接。 It basically means that you compiled a bunch of implementation files into object files or lib

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值