当前位置:网站首页>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 language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
- Optical blood pressure estimation based on PPG and FFT neural network [translation]
- AvL树的实现
- SQL injection Foundation
- 安装及管理程序
- 上海部分招工市场对新冠阳性康复者拒绝招录
- 2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
- Method of accessing mobile phone storage location permission under non root condition
- QLabel 跑马灯文字显示
- 倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
猜你喜欢
ACTF 2022圆满落幕,0ops战队二连冠!!
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller
Breadth first traversal of graph
多线程基础:线程基本概念与线程的创建
五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”
helm部署etcd集群
提前解锁 2 大直播主题!今天手把手教你如何完成软件包集成?|第 29-30 期
When visual studio code starts, it prompts "the code installation seems to be corrupt. Please reinstall." Solution to displaying "unsupported" information in the title bar
There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
基于ppg和fft神经网络的光学血压估计【翻译】
随机推荐
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller
驼峰式与下划线命名规则(Camel case With hungarian notation)
助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!
R语言ggplot2可视化时间序列柱形图:通过双色渐变配色颜色主题可视化时间序列柱形图
[paper notes] transunet: transformers make strongencoders for medical image segmentation
Describe the process of key exchange
关于npm install 报错问题 error 1
Qlabel marquee text display
[Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
C#/VB.NET 给PDF文档添加文本/图像水印
C#/VB. Net to add text / image watermarks to PDF documents
10、 Process management
渲大师携手向日葵,远控赋能云渲染及GPU算力服务
Airiot IOT platform enables the container industry to build [welding station information monitoring system]
R language uses rchisq function to generate random numbers that conform to Chi square distribution, and uses plot function to visualize random numbers that conform to Chi square distribution
Implementation of AVL tree
About static type, dynamic type, ID, instancetype
Graffiti intelligence is listed on the dual main board in Hong Kong: market value of 11.2 billion Hong Kong, with an annual revenue of 300 million US dollars
Understanding disentangling in β- VAE paper reading notes
裕太微冲刺科创板:拟募资13亿 华为与小米基金是股东