当前位置:网站首页>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. 所以, 一目了然了。
边栏推荐
- Estimate blood pressure according to PPG using spectral spectrum time depth neural network [turn]
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- 包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
- Describe the process of key exchange
- 朗坤智慧冲刺科创板:年营收4亿 拟募资7亿
- 关于静态类型、动态类型、id、instancetype
- R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图
- AcWing 3537.树查找 完全二叉树
- Penetration test information collection - basic enterprise information
- How word displays modification traces
猜你喜欢

2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目

如何提高网站权重

Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up

pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法

About NPM install error 1

How to improve website weight

Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion

AvL树的实现

朗坤智慧冲刺科创板:年营收4亿 拟募资7亿

五金机电行业供应商智慧管理平台解决方案:优化供应链管理,带动企业业绩增长
随机推荐
ROS custom message publishing subscription example
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
Analysis of frequent chain breaks in applications using Druid connection pools
基于蝴蝶种类识别
青龙面板最近的库
星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
驼峰式与下划线命名规则(Camel case With hungarian notation)
None of the strongest kings in the monitoring industry!
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
上海部分招工市場對新冠陽性康複者拒絕招錄
How word displays modification traces
C#/VB. Net to add text / image watermarks to PDF documents
Qlabel marquee text display
R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
The role of applet in industrial Internet
第五期个人能力认证考核通过名单公布
业务与应用同步发展:应用现代化的策略建议
Stm32+esp8266+mqtt protocol connects onenet IOT platform
About NPM install error 1