[英]C Programming undefined reference to `WinMain@16'
I'm trying to compile following code using gcc (tdm-1) 4.7.1 with notepad, and command prompt on windows 10. previously add bin folder path to global variables,but when i try to compile i get following error " undefined reference to `WinMain@16'".However same code works fine with codeblocks!.我正在尝试使用带有记事本的 gcc (tdm-1) 4.7.1 和 Windows 10 上的命令提示符编译以下代码。以前将 bin 文件夹路径添加到全局变量,但是当我尝试编译时出现以下错误“未定义引用到`WinMain@16'"。但是相同的代码在代码块上也能正常工作!。
PS: I compile it like this "cd /d path of code then gcc filename.c" PS:我像这样编译它“cd /d path of code then gcc filename.c”
#include<stdio.h>
int main(){
printf("Hello world");
return 0;
}
我偶然发现出了什么问题。通过记事本编写代码后,我忘记保存文件 ctrl+s,所以我只是尝试编译空文件。
This is strange.这很奇怪。
gcc --version
gcc.exe (tdm64-1) 5.1.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software;
gcc.exe (tdm64-1) 5.1.0 版权所有 (C) 2015 Free Software Foundation, Inc。这是免费软件; see the source for copying conditions.
请参阅复制条件的来源。 There is NO warranty;
没有保修; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
甚至不是为了特定目的的适销性或适合性
Without any options I get我没有任何选择
gcc filename.c
a.exe
Hello world
你好,世界
Notice however但是请注意
gcc -municode filename.c
Generates a linker error生成链接器错误
D:/bin-win64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_w.o)
: In functionwmain
:C:/crossdev/src/mingw-w64-v4-git/mingw-w64-crt/crt/crt0_w.c:23
: undefined reference towWinMain
collect2.exe
: error:ld
returned 1 exit statusD:/bin-win64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_w.o)
: 在函数wmain
:C:/crossdev/src/mingw-w64-v4-git/mingw-w64-crt/crt/crt0_w.c:23
: 未定义引用wWinMain
collect2.exe
:错误:ld
返回 1 个退出状态
The startup function in MinGW is mainCRTStartup
, which calls main. MinGW 中的启动函数是
mainCRTStartup
,它调用 main。 If there is no user specified main
, the runtime provides one for you, that one calls WinMain
.如果没有用户指定
main
,则运行时会为您提供一个调用WinMain
。
So your app should compile from the command line as well.所以你的应用程序也应该从命令行编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.