函数'check'的未定义引用(MinGW中的GCC编译)

时间:2022-04-04 11:45:52

I seem to be getting the rookie error where it says, undefined reference to 'check', as shown below:

我似乎得到了菜鸟错误,它说,未定义引用'check',如下所示:

函数'check'的未定义引用(MinGW中的GCC编译)

This should not be a problem, as I have in fact made a check.h and included in hiker.c, as shown below:

这应该不是问题,因为我实际上制作了一个check.h并包含在hiker.c中,如下所示:

函数'check'的未定义引用(MinGW中的GCC编译)

Does anybody know the source of this problem? I have just started using MinGW(as I wanted to learn programming C on Windows).

有人知道这个问题的根源吗?我刚开始使用MinGW(因为我想在Windows上学习编程C)。

Here is a picture of the main function. I can add the code too if necessary:

这是主要功能的图片。如有必要,我也可以添加代码:

函数'check'的未定义引用(MinGW中的GCC编译)

1 个解决方案

#1


2  

I guess that check function is implemented in a file check.c

我想检查函数是在check.c文件中实现的

You must link that file also, because of your check.h export the prototype to let the compiler know how the check function is structured, but the linker needs the check function code compiled and reachable.

您还必须链接该文件,因为您的check.h导出原型以让编译器知道检查函数的结构,但链接器需要编译和可访问的检查函数代码。

What you need is to compile using a command like this:

你需要的是使用这样的命令编译:

gcc -Wall hiker.c check.c -o hiker.exe

Take also note that linker is giving you another error about WinMain@16 This means that you started a windows application project, I guess you must change your project to console project type.

另请注意,链接器正在为您提供有关WinMain @ 16的另一个错误。这意味着您启动了一个Windows应用程序项目,我想您必须将项目更改为控制台项目类型。

#1


2  

I guess that check function is implemented in a file check.c

我想检查函数是在check.c文件中实现的

You must link that file also, because of your check.h export the prototype to let the compiler know how the check function is structured, but the linker needs the check function code compiled and reachable.

您还必须链接该文件,因为您的check.h导出原型以让编译器知道检查函数的结构,但链接器需要编译和可访问的检查函数代码。

What you need is to compile using a command like this:

你需要的是使用这样的命令编译:

gcc -Wall hiker.c check.c -o hiker.exe

Take also note that linker is giving you another error about WinMain@16 This means that you started a windows application project, I guess you must change your project to console project type.

另请注意,链接器正在为您提供有关WinMain @ 16的另一个错误。这意味着您启动了一个Windows应用程序项目,我想您必须将项目更改为控制台项目类型。