当前位置:网站首页>GCC【7】- 编译检查的是函数的声明,链接检查的是函数的定义bug
GCC【7】- 编译检查的是函数的声明,链接检查的是函数的定义bug
2022-07-06 11:17:00 【大城市的小蜗牛】
项目场景:
- 最近遇到一个问题, 下面来简化说下:
// int xxx();
int main()
{
xxx();
}
- 编译一下,自然编译不过, 信息为:
[email protected]:~/taoge/cpp/test$ g++ -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:5:9: error: ‘xxx’ was not declared in this scope
xxx();
^
[email protected]:~/taoge/cpp/test$
- 打开上述的注释, 得到:
int xxx();
int main()
{
xxx();
}
- 编译一下, 能通过吗? 看看:
[email protected]:~/taoge/cpp/test$ g++ -c main.cpp
[email protected]:~/taoge/cpp/test$
- 链接一下, 发现xxx()未定义。
[email protected]:~/taoge/cpp/test$ g++ main.o
main.o: In function `main': main.cpp:(.text+0x5): undefined reference to `xxx()'
collect2: error: ld returned 1 exit status
从而印证题目中的问题。
我当时的纳闷是, xxx函数没有定义, 居然能通过编译。 确实能。 要区分编译和链接所做的事。
再仔细看看上述的英文提示, 编译不通过, 显示的是not declared, 而链接不通过, 显示的是undefined. 所以, 一目了然了。
边栏推荐
- R语言dplyr包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组均值(mean)
- Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers
- This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
- How to improve website weight
- node の SQLite
- Binary search tree
- R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the grouped dot strip plot, and set the add parameter to add box plots for different levels of dot strip
- 巨杉数据库首批入选金融信创解决方案!
- Specify flume introduction, installation and configuration
- Penetration test information collection - basic enterprise information
猜你喜欢
Method of accessing mobile phone storage location permission under non root condition
[Matlab] Simulink 同一模块的输入输出的变量不能同名
Docker installation redis
Analysis of frequent chain breaks in applications using Druid connection pools
Oracle advanced (IV) table connection explanation
Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
Collection of penetration test information -- use with nmap and other tools
[depth first search] Ji suanke: a joke of replacement
Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
随机推荐
同宇新材冲刺深交所:年营收9.47亿 张驰与苏世国为实控人
Estimate blood pressure according to PPG using spectral spectrum time depth neural network [turn]
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
基于蝴蝶种类识别
Method of accessing mobile phone storage location permission under non root condition
Use map function and split function to type multiple elements in one line
Self supervised heterogeneous graph neural network with CO comparative learning
Execution process of MySQL query request - underlying principle
Penetration test information collection - App information
C#/VB. Net to add text / image watermarks to PDF documents
[depth first search] Ji suanke: a joke of replacement
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置add参数为不同水平点状条带图添加箱图
星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
Digital "new" operation and maintenance of energy industry
Helm deploy etcd cluster
Word如何显示修改痕迹
关于静态类型、动态类型、id、instancetype
巨杉数据库首批入选金融信创解决方案!
Human bone point detection: top-down (part of the theory)