当前位置:网站首页>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语言ggplot2可视化时间序列柱形图:通过双色渐变配色颜色主题可视化时间序列柱形图
- R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
- AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
- Analysis of frequent chain breaks in applications using Druid connection pools
- Human bone point detection: top-down (part of the theory)
- Solve DoS attack production cases
- Pytorch common loss function
- 2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
- 多线程基础:线程基本概念与线程的创建
- QLabel 跑马灯文字显示
猜你喜欢
Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!
用于远程医疗的无创、无袖带血压测量【翻译】
ROS自定义消息发布订阅示例
【论文笔记】TransUNet: Transformers Make StrongEncoders for Medical Image Segmentation
倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
Online notes
AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
随机推荐
Airiot IOT platform enables the container industry to build [welding station information monitoring system]
Handwritten online chat system (principle part 1)
提前解锁 2 大直播主题!今天手把手教你如何完成软件包集成?|第 29-30 期
[Matlab] Simulink 同一模块的输入输出的变量不能同名
Docker installation redis
test about BinaryTree
Hongke shares | plate by plate ar application in Beijing Winter Olympics
Breadth first traversal of graph
朗坤智慧冲刺科创板:年营收4亿 拟募资7亿
Binary search tree
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
About NPM install error 1
Some recruitment markets in Shanghai refuse to recruit patients with covid-19 positive
Deep circulation network long-term blood pressure prediction [translation]
node の SQLite
巨杉数据库首批入选金融信创解决方案!
AutoCAD - what is the default lineweight for centerline drawing and CAD? Can I modify it?
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
关于静态类型、动态类型、id、instancetype
多线程基础:线程基本概念与线程的创建