简体   繁体   English

错误对“ WinMain @ 16”的未定义引用

[英]Error Undefined reference to 'WinMain@16'

Can a program be written without main() function? 可以在没有main()函数的情况下编写程序吗?

I have written this code and saved a filename as withoutmain.c and getting an error as 我已经编写了这段代码,并将文件名保存为withoutmain.c并收到错误消息为

undefined reference to 'WinMain@16'"

My code 我的密码

 #include<stdio.h>
    #include<windows.h>
    extern void _exit(register int code);
    _start(){
      int retval;
      retval=myFunc();
      _exit(retval);
    }
    int myFunc(void){
     printf("Hiii Pratishtha");
     return 0;
    }

Please provide me the solution of this problem and also the proper memory construction of code and what is happening at the compiler end of this program. 请向我提供此问题的解决方案,以及代码的正确内存构造以及该程序的编译器端发生的情况。 Thank you! 谢谢!

Can a program be written without main() function? 可以在没有main()函数的情况下编写程序吗?

Yes there can be a C program without a main function. 是的,可以有一个没有主要功能的C程序。 I would suggest two solutions....... 我会建议两种解决方案。

1) Using a macro that defines main 1)使用定义main的宏

#include<stdio.h>
#include<windows.h>
#define _start main
extern void _exit(register int code);

int myFunc(void){
    printf("Hiii Pratishtha");
    return 0;
}

int _start(){
     int retval;
     retval=myFunc();
     _exit(retval);
}

2) Using Entry Point (Assuming you are using visual studio) 2) 使用入口点(假设您正在使用Visual Studio)

To set this linker option in the Visual Studio development environment 在Visual Studio开发环境中设置此链接器选项

/ENTRY:function

A function that specifies a user-defined starting address for an .exe file or DLL. 为.exe文件或DLL指定用户定义的起始地址的函数。

  1. Open the project's Property Pages dialog box. 打开项目的“属性页”对话框。 For details, see Setting Visual C++ Project Properties. 有关详细信息,请参见设置Visual C ++项目属性。
  2. LClick the Linker folder. L单击链接器文件夹。
  3. Click the Advanced property page. 单击高级属性页面。
  4. Modify the Entry Point property. 修改入口点属性。

OR 要么

if you are using gcc then 如果您使用的是gcc

-Wl,-e_start

the -Wl ,... thing passes arguments to the linker, and the linker takes a -e argument to set the entry function -Wl ,...事物将参数传递给链接器,并且链接器采用-e参数来设置入口函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gradle未定义引用`WinMain @ 16&#39;错误 - Gradle undefined reference to `WinMain@16' error 未定义的'WinMain @ 16'C错误引用 - Undefined reference to 'WinMain@16' C error C:未定义对“WinMain@16”的引用 - C: undefined reference to "WinMain@16' C 编程对‘WinMain@16’的未定义引用 - C Programming undefined reference to `WinMain@16' 无法在 CodeBlocks 上编译 C 程序:未定义对“WinMain@16”的引用 - Cannot compile C programs on CodeBlocks: Undefined reference to 'WinMain@16' 未定义对“WinMain@16”collect2.exe 的引用:错误:ld 返回 1 退出状态 - undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status 我刚开始编码,但在 vscode 中出现了 undefined reference to winmain@16 这个错误 - I just started coding and I got this error undefined reference to winmain@16 in vscode 未定义引用“ WinMain @ 16” mingw转换为DLL - undefined reference to `WinMain@16' mingw converting to DLL 使用SDL时对WinMain @ 16的未定义引用 - Undefined reference to WinMain@16 when using SDL 未定义对“ SDL_Init”的引用(对“ WinMain @ 16” collect2.exe的未定义引用:错误:ld返回了1个退出状态) - undefined reference to `SDL_Init' (undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM