C/C++常见错误汇总

版权声明:可转载,需要明确注明转载出处和链接;不允许商业用途。 https://blog.csdn.net/bengxu/article/details/82750233

笔记本:MacBook Air,操作系统:macOS,IDE:CLion,工具链如下图:
在这里插入图片描述

1.error: C++ requires a type specifier for all declarations

出错原因: 代码片段没有写在函数中。
解决方法: 将代码片段写进函数中。

2.ld: symbol(s) not found for architecture x86_64

出错原因: main.cpp中没有找到对应的函数名声明,没有在.cpp引用包含该函数名的头文件.h。
解决方法: 引入对应头文件。

3.ld: 1 duplicate symbol for architecture x86_64

出错原因:
main.cpp中和其它.c文件同时引入了相同的头文件,在main.cpp中调用头文件中的函数报错。
比如test.c和main.cpp同时通过include引入了test.h,然后再main.cpp中调用test.h中的printTest()函数。
解决方法:
去除test.c对test.h的引用。

猜你喜欢

转载自blog.csdn.net/bengxu/article/details/82750233