eclipse + cdt + mingw + windows 错误“未定义对‘WinMain@16’的引用”构建时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3269112/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:51:11  来源:igfitidea点击:

eclipse + cdt + mingw + windows error "undefined reference to `WinMain@16'" on build

windowseclipsemingweclipse-cdt

提问by olamundo

I installed eclipse, cdt and mingw on my windows XP machine. added C:\MinGW\binto my PATH.

我在 Windows XP 机器上安装了 eclipse、cdt 和 mingw。添加C:\MinGW\bin到我的路径。

Created a new c++ project, with one file in it, test.c. the code in it:

创建了一个新的 c++ 项目,其中包含一个文件 test.c。其中的代码:

int main(){
   int i=1;
}

Trying to build, I get the error: /mingw/lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to 'WinMain@16'

尝试构建,我收到错误: /mingw/lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to 'WinMain@16'

Notice it's not complaining about test.cbut rather about some main.cin one of mingw's libs.

请注意,它不是在抱怨,test.c而是main.c在 mingw 的库之一中抱怨。

What am I doing wrong?

我究竟做错了什么?

回答by Gregory

You need to save the .cfile first.

您需要先保存.c文件。

回答by olamundo

well, the solution was really weird, but I guess it would make sense to someone more proficient with CDT than me - My main() was inside a .c file. When I changed the suffix to be .cpp, it worked like a charm.

嗯,这个解决方案真的很奇怪,但我想这对于比我更精通 CDT 的人来说是有意义的 - 我的 main() 在一个 .c 文件中。当我将后缀更改为 .cpp 时,它就像一个魅力。

回答by Adam Mitz

main.o from libmingw32.a should not be searched by the linker because the undefined symbol _main from crt2.o is (should be) satisfied by the "int main()" which you wrote.

链接器不应搜索 libmingw32.a 中的 main.o,因为来自 crt2.o 的未定义符号 _main(应该)由您编写的“int main()”满足。

Please copy & paste the gcc command lines that cdt is executing.

请复制并粘贴 cdt 正在执行的 gcc 命令行。