[英]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指定用户定义的起始地址的函数。
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.