使用int main(void)编译失败; main(int argc,char * argv [])成功。为什么? [英] Compiling with int main(void) fails; main(int argc, char *argv[]) succeeds. Why?

查看:393
本文介绍了使用int main(void)编译失败; main(int argc,char * argv [])成功。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要编译具有 int main(void) main函数的程序不同于编译如果程序不使用在命令行上传递的参数,则程序具有 int main(int argc,char * argv []) main函数

Why would compiling a program which has an int main(void) main function differ from compiling a program which has an int main(int argc, char *argv[]) main function, if the program does not use arguments passed on the command line?

这个操作系统或编译器是特定的吗?我不会得到相同的结果使用mingw和g ++ (这是奇怪的不是因为wingw是gcc的港口)

Is this OS or compiler specific? I do not get the same results using mingw and g++(which is weird isn't it as wingw is a port of gcc).

#include <iostream>
#include"SDL/SDL.h"
int main(void)
{
    return 0;
}



编译命令



Compilation commands

g++ test.cpp; #g++ 4.4.5
i586-mingw32msvc-g++ test.cpp; # mingw 4.4.4



错误



(由第二个命令给定。)

Error

(Given by the second command.)

a(main.o):(.text+0x85): undefined reference to `_WinMain@16'


推荐答案

在Windows上,当您包括 SDL.h main 被重新定义为 SDL_main 调用 WinMain (非控制台Windows应用程序的真正入口点),做一些初始化,最后调用你的主要代码。它有一个签名 argc argv ,你几乎需要遵循它,所以 int main()将无法工作。

This is SDL thing. On Windows, when you include SDL.h,main is redefined to SDL_main which calls WinMain (the real entry point in non-console Windows apps), does some initialization and finally calls your main code. It has a signature with argc and argv and you're pretty much required to follow it, so int main() won't work.

这篇关于使用int main(void)编译失败; main(int argc,char * argv [])成功。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆