其他分享
首页 > 其他分享> > codeblocks 主函数调用其他文件的函数时报错:"error:undefined reference to xxx"

codeblocks 主函数调用其他文件的函数时报错:"error:undefined reference to xxx"

作者:互联网

1、有三个文件file1.c,file2.c,file3.c分别定义了三个函数用来输入字符串、删除字符、输出字符串。有test.c用来测试对输入字符串中的指定字符进行删除。test.c中的main()函数中用extern声明用到的三个函数是在其他文件中定义的外部函数。

 

 2、运行报错如下:

 

3、解决办法为:将file1.c,file2.c,file3.c中定义的函数写到三个.h文件中,这里命名为file1.h,file2.h,file3.h,同时在主函数即test.c的文件头增加 #include "file1.h"、#include "file2.h"、 #include "file3.h"。再次编译运行成功

 

标签:file3,file2,file1,函数,reference,xxx,函数调用,test,include
来源: https://www.cnblogs.com/z-blogs/p/12395249.html