eclipse 对“WinMain@16”C 错误的未定义引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13459912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined reference to 'WinMain@16' C error
提问by Yanika Abela
I am using Eclipse (C programming) and I have come up with this code but every time I build it, I get the error saying, "Undefined Reference to 'WinMain@16'". I have spent over 2 hours trying to solve this problem but I can't figure out my where my error is. Can anyone help?
我正在使用 Eclipse(C 编程)并且我想出了这个代码,但是每次我构建它时,我都会收到错误消息,“未定义对 'WinMain@16' 的引用”。我花了 2 个多小时试图解决这个问题,但我无法弄清楚我的错误在哪里。任何人都可以帮忙吗?
This is the code:
这是代码:
#include <stdio.h>
int main(void)
{
int input;
printf("Please enter an integer:\n");
scanf("%d",&input);
int temp = input;
while(input<=temp+10)
{
printf("%d ",input);
input++;
}
printf("\n");
return 0;
}
回答by huysentruitw
When you compile or build, files are not automatically saved to disk by Eclipse. But the compiler is using the on-disk files. So maybe you just didn't save the file after you've added the main function.
编译或构建时,Eclipse 不会自动将文件保存到磁盘。但是编译器正在使用磁盘文件。所以也许你只是在添加了 main 函数后没有保存文件。
回答by Toribio
If you are compiling the right and saved file, you have to make sure you are compiling it with the subsystem target set to console, when you're using the main
entry point.
如果您正在编译正确且已保存的文件,则必须确保在使用main
入口点时将子系统目标设置为控制台来编译它。
You can do this changing the makefile.
您可以通过更改生成文件来执行此操作。
If you don't know how to do this, or if you're not using a makefile and don't want to change the compiler's parameters line, you can use this directive:
如果您不知道如何执行此操作,或者您没有使用 makefile 并且不想更改编译器的参数行,则可以使用以下指令:
#pragma comment(linker, "/subsystem:console")
WinMain
is normally used for /subsystem:windows
type of programs, and as you are trying to make a console application, you should use /subsystem:console
and the main
entry point.
WinMain
通常用于/subsystem:windows
程序类型,当您尝试制作控制台应用程序时,您应该使用/subsystem:console
和main
入口点。
Again, make sure you are compiling the right file on the disk.
再次确保您在磁盘上编译了正确的文件。