当前位置:网站首页>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. 所以, 一目了然了。
边栏推荐
- Some recruitment markets in Shanghai refuse to recruit patients with covid-19 positive
- About NPM install error 1
- None of the strongest kings in the monitoring industry!
- 被疫情占据的上半年,你还好么?| 2022年中总结
- Implementation of AVL tree
- Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan
- 包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
- The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
- Execution process of MySQL query request - underlying principle
- Camel case with Hungarian notation
猜你喜欢

Jushan database was among the first batch of financial information innovation solutions!

渲大师携手向日葵,远控赋能云渲染及GPU算力服务

AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?

MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!

美庐生物IPO被终止:年营收3.85亿 陈林为实控人

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

巨杉数据库首批入选金融信创解决方案!

AvL树的实现

The role of applet in industrial Internet

wx小程序学习笔记day01
随机推荐
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
Cobra quick start - designed for command line programs
使用map函数、split函数一行键入多个元素
Multithreading Basics: basic concepts of threads and creation of threads
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
人体骨骼点检测:自顶向下(部分理论)
tensorflow和torch代码验证cuda是否安装成功
This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
Test 1234
AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
ORACLE进阶(四)表连接讲解
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
Wx applet learning notes day01
On AAE
Understanding disentangling in β- VAE paper reading notes
C#/VB.NET 给PDF文档添加文本/图像水印
Stm32+esp8266+mqtt protocol connects onenet IOT platform
Specify flume introduction, installation and configuration
R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
手写一个的在线聊天系统(原理篇1)