当前位置:网站首页>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. 所以, 一目了然了。
边栏推荐
- Abstract classes and abstract methods
- MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!
- R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
- ROS custom message publishing subscription example
- Optical blood pressure estimation based on PPG and FFT neural network [translation]
- Multithreading Basics: basic concepts of threads and creation of threads
- How to improve website weight
- C#/VB.NET 给PDF文档添加文本/图像水印
- Describe the process of key exchange
- R语言使用dt函数生成t分布密度函数数据、使用plot函数可视化t分布密度函数数据(t Distribution)
猜你喜欢

Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan

Describe the process of key exchange

【论文笔记】TransUNet: Transformers Make StrongEncoders for Medical Image Segmentation

人体骨骼点检测:自顶向下(部分理论)

Digital "new" operation and maintenance of energy industry

SQL injection - access injection, access offset injection
![[Matlab] Simulink 同一模块的输入输出的变量不能同名](/img/99/adfe50075010916439cd053b8f04c7.png)
[Matlab] Simulink 同一模块的输入输出的变量不能同名

Word如何显示修改痕迹

The role of applet in industrial Internet

线代笔记....
随机推荐
关于静态类型、动态类型、id、instancetype
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
人体骨骼点检测:自顶向下(部分理论)
pytorch常见损失函数
业务与应用同步发展:应用现代化的策略建议
Self supervised heterogeneous graph neural network with CO comparative learning
R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
[depth first search] Ji suanke: find numbers
Test 123
Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
Describe the process of key exchange
Solve DoS attack production cases
被疫情占据的上半年,你还好么?| 2022年中总结
Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
From 2022 to 2024, the list of cifar azrieli global scholars was announced, and 18 young scholars joined 6 research projects
2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
Method of accessing mobile phone storage location permission under non root condition