————新手必备:从编译错误到运行崩溃,一篇搞定

前言

Dev-C++ 是许多 C/C++ 初学者的入门 IDE,但其报错信息有时不够直观,容易让人一头雾水。本文整理了一些高频错误及其解决方法,希望能帮你节省调试时间。

错误速查表

DeepSeek给的通用报错及解决方案

我的报错与解决方案

序号 问题 解决方案
1 typedef int bool;
#define true 1
#define false 0
4 13 D:\桌面\ModelFactory\Implement\Linear_sequentialList.h [Error] two or more data types in declaration specifiers
使用已有BOOL三方库
#include <stdbool.h>
2 13 2 D:\桌面\ModelFactory\Implement\Linear_sequentialList.h [Error] unknown type name 'SqList' 定义基础类型 int/double/float/bool内存基址
3 11 23 D:\桌面\ModelFactory\Implement\Linear_sequentialList.h [Error] expected ';' before 'typedef' C语言行末缺少;符号
4 11 3 D:\桌面\ModelFactory\Implement\Linear_sequentialList.c [Error] 'L' is a pointer; did you mean to use '->'? 指针用->指向成员变量
5 7  D:\桌面\ModelFactory\main.c [Error] unterminated #ifdef 既然#ifdef #elifdef #endif 不存在,那么用#ifdef #endif #ifdef #endif便行
6 9 2 D:\桌面\ModelFactory\main.c [Warning] implicit declaration of function 'log_info' [-Wimplicit-function-declaration] log.h不能被隐式调用,
#include "./Implement/log.h"
7 27 86 D:\桌面\ModelFactory\Implement\Linear_sequentialList.c [Error] 'ElemTypes' undeclared (first use in this function); did you mean 'ElemType'? ElemTypes拼写错误
8 编译窗口不见了 原文链接:https://blog.csdn.net/weixin_45846799/article/details/120685787
9 7 13 D:\桌面\ModelFactory\Implement\Linear_LinkList.h [Error] conflicting types for 'ElemType' make clean再次执行编译
10 8 13 D:\桌面\ModelFactory\Implement\Linear_LinkList.h [Error] conflicting types for 'ElemType' typedef float ElemType_float;
typedef int ElemType_int;
11 D:\桌面\ModelFactory\collect2.exe [Error] ld returned 1 exit status
C:\Program Files (x86)\Embarcadero\Dev-Cpp\TDM-GCC-64\x86_64-w64-mingw32\bin\ld.exe Implement/Linear_LinkList.o:Linear_LinkList.c:(.text+0x166): multiple definition of `PrintList'; Implement/Linear_List.o:Linear_List.c:(.text+0x268): first defined here
改个名字
12 19 2 D:\桌面\ModelFactory\main.c [Warning] implicit declaration of function 'Print_LinkList'; did you mean 'PrintList'? [-Wimplicit-function-declaration] 函数实现忘记更新头文件了
13 26 30 D:\桌面\ModelFactory\Implement\Linear_LinkList.c [Warning] implicit declaration of function 'malloc' [-Wimplicit-function-declaration] 在C语言中,使用 malloc 需要包含 <stdlib.h> 头文件,否则编译器会假设 malloc 返回 int 类型(隐式声明),导致警告和潜在的错误。
14 指针使用 C语言只支持值传递,函数内修改参数不影响外部,调用后外部指针仍为默认值。所有结果return见证。
15 14 2 D:\桌面\ModelFactory\include\Stack_LIFO.h [Error] unknown type name 'ElemType_Stak'
typedef int ElemType_Stak;
拼写错误
16 11 9 D:\桌面\ModelFactory\include\Stack_LIFO.h [Warning] ISO C99 requires whitespace after the macro name #define STACKINCREMENT 10; //存储空间 分配增量
17 8 9 D:\桌面\ModelFactory\include\Stack_LIFO.c [Warning] implicit declaration of function 'LOG_ERROR' [-Wimplicit-function-declaration] 大小写区分
18 如何获取文件组织 CMD
ls -R
# 或者更美观的树形
tree /F >>
/F 显示每个文件夹中的文件名,/A 使用 ASCII 字符而非图形字符。
POWERSHELL
Get-ChildItem -Recurse | Select-Object FullName
# 或者更美观的树形
tree.com /F
19 C:\Program Files (x86)\Embarcadero\Dev-Cpp\TDM-GCC-64\x86_64-w64-mingw32\bin\ld.exe Implement/?筛?新?罩?库?跋?有?罩?库?得?/log_auto.o:log_auto.c:(.text+0x24a): multiple definition of `log_set_level'; Implement/log.o:log.c:(.text+0x24a): first defined here 中文路径,从project移除

通用排查步骤

1. **红色错误看第一行**:编译器报错往往一串,最上面的才是根本原因。
2. **双击报错行**:Dev-C++ 会跳转到大致位置,检查前后几行代码。
3. **确认编译器设置**:工具 → 编译选项 → 勾选“编译时加入以下命令” → 填入 `-std=c++11`(若需 C++11 特性)。
4. **清理并重新编译**:执行“工具 → 清除历史记录”,再重新编译运行。

结语

遇到报错不用慌,大多数都是语法或配置问题。建议将本文提到的几种常见错误保存下来,下次遇到时直接对照排查。如果你有其他疑难报错,欢迎在评论区留言,我们一起完善这份列表。

*整理日期:Day0607 | 适用 Dev-C++ 5.11 及以上版本*

更多推荐