惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
T
Tenable Blog
博客园_首页
S
Securelist
Spread Privacy
Spread Privacy
Google Online Security Blog
Google Online Security Blog
Forbes - Security
Forbes - Security
Engineering at Meta
Engineering at Meta
U
Unit 42
L
LINUX DO - 热门话题
量子位
T
Threat Research - Cisco Blogs
博客园 - 【当耐特】
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
Martin Fowler
Martin Fowler
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Security Latest
Security Latest
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
Know Your Adversary
Know Your Adversary
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
V2EX - 技术
V2EX - 技术
T
Tailwind CSS Blog
月光博客
月光博客
Recent Announcements
Recent Announcements
G
Google Developers Blog
F
Full Disclosure
W
WeLiveSecurity
宝玉的分享
宝玉的分享
腾讯CDC
G
GRAHAM CLULEY
Vercel News
Vercel News
Simon Willison's Weblog
Simon Willison's Weblog
美团技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security

Ayx 博客

PaperMC 服务器允许刷线机/无头活塞等配置 如何从 YouTube 搬运视频?如何做一个合格的 YouTube 搬运工?我搬运视频的方法与原则 此博客的所有镜像 免费获取在 Microsoft Store 中收费 ¥7.00 的 HEVC 视频扩展 CLI Post Test moefox.tech 已于 7 月 25 日过期,本站域名已更换为 imayx.top 关于 链接 LG V50 ThinQ 韩版 LGU+ 从解锁 BootLoader 到破解 VoLTE / NSA 5G、从刷入第三方 Recovery 到硬格、从混刷到黑砖全教程 Python 3 入门学习笔记 新年快乐 & 本站的改版 在 Hugo 主题 Stack 中轻松配置 Waline 评论系统 MySSL 安全签章 题解 P1603 斯诺登的密码 安装 Hugo 主题 Stack 时你可能会遇到的问题 独角兽搜索 Hello Hugo 题解 UPC-1488 客户调查(client) 题解 P5707 【深基2.例12】上学迟到 题解 P2669 [NOIP2015 普及组] 金币 题解 P5719 【深基4.例3】分类平均 分享一下我的博客园在用的修改版 Wider Gao 博客园主题 使用 Node.js(安装Hexo)时出现了 rollbackFailedOptional 错误的解决方法 题解 HDU2063 过山车 题解 YBT 1000:入门测试题目 题解 P1650 田忌赛马 OJ术语的解释: AC、WA、TLE、OLE、MLE、RE、PE、CE、UKE 都是些啥? 归档 搜索 友链
出现 error: ld returned 1 exit status 的五种原因以及解决方法
2021-08-22 · via Ayx 博客

Featured image of post 出现 error: ld returned 1 exit status 的五种原因以及解决方法

CSDN 等国内平台上的文章只提到了一丁点,故看了半天 Stack OverFlow 后写篇博客解释

这个错误让人懵圈的地方就在于它不会给出错误出现的位置,让已经写了几百行的你痛不欲生。

可执行文件被占用了

因此编译器无法覆盖旧的可执行文件,所以编译失败。

这很有可能是你没发现它还没结束运行。

(我目前在用的 IDE:Visual Studio Code

扩展:C/C++ Compile Run(可以方便地编译单个 cpp 文件,且不会因为路径中存在空格或中文出错。)

解决方案

Dev C++ 等 IDE 直接把弹出的窗口(黑框)关了就行了

VS Code 可以从输出切换到终端选项卡,使用快捷键 Ctrl+C 结束程序(同样适用于 external console )。

实在不行就用任务管理器和 taskkill 吧

主函数不存在(main 拼写错误)

你不太可能不写主函数,但是你很有可能把 main 打成 mian 或者什么其他奇怪的东西。

在编译器眼里,这些可不能算主函数。

解决方案

main 拼对。

所调用的函数仅进行了声明

这种情况下新版编译器仍旧会输出 error: ld returned 1 exit status 这一让人迷惑的错误。 但是一般也不会把函数体和声明分开写吧…

(函数声明在主函数上方即可,函数体是可以写在 main 函数下方的。)

解决方案

把漏写了的函数体补上。

(旧版编译器)在主函数中定义了函数

新版编译器发现你在 main 函数中定义了其它函数报错并不是error: ld returned 1 exit status

而是error: a function-definition is not allowed here before '{' token Snipaste_2021-08-22_19-30-32.png

解决方案

把子函数定义在主函数外面。

(旧版编译器)调用了不存在的函数

一般情况下应该是所需头文件未引入或者函数名键入错误。

并不确定“scanf/printf 键入错误”是不是真的会引起该错误(CSDN 上的一篇博客说的,我也懒得去装个旧版编译器实测),是不是只有 scanf 和 printf 会这样更不得而知…

总之新版编译器即使在 CSDN 博文中所谓的“代码较多的情况”下也不会因为这个原因出现这种错误,只会告诉你这个函数在这个作用域没有被定义过,甚至还会反问你:

你说的是 scanf 吗?

(测试用代码是随机跳题后从这里复制的,并未提交评测)

解决方案

检查函数名称的拼写是否正确。

如果想调用库函数但不清楚应该引入什么头文件,可以在搜索引擎上像这样搜索:

sqrt() 所在的头文件

C++ sqrt()

C语言 sqrt()

或者直接 #include <bits/stdc++.h>

本文的测试环境

1
2
3
4
g++ (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编辑记录

2021-08-22 19:20:00