简体   繁体   English

未定义对“WinMain@16”collect2.exe 的引用:错误:ld 返回 1 退出状态

[英]undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status

I am using eclipse CDT to test the Intel instructions and below is my program:我正在使用 eclipse CDT 来测试英特尔指令,下面是我的程序:

#define cpuid(func,ax,bx,cx,dx)\
__asm__ __volatile__ ("cpuid":\
 "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
int Check_CPU_support_AES()
 {
 unsigned int a,b,c,d;
 cpuid(1, a,b,c,d);
 return (c & 0x2000000);
 }

When I compile the above code, I get linkage error as:当我编译上面的代码时,出现链接错误:

Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\Intel.o" "..\\src\\Intel.c" 
gcc -o Intel.exe "src\\Intel.o" 
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

Please help me regarding the issue.请帮我解决这个问题。

Your program isn't complete.你的程序不完整。 You need to implement the OS-expected entry point.您需要实现操作系统预期的入口点。 In your case, that looks like it's called WinMain .在您的情况下,它看起来像是WinMain

Yes, Main () function is missing and the compiler is not able to find an entry point for executing the program.是的,缺少 Main() 函数,编译器无法找到执行程序的入口点。

One more reason is even if you have written the main function but if you didnot save the .cpp file and try to compile it will give the same error.So make sure you have successfully saved the .cpp file and then compile and run your code.另一个原因是,即使您已经编写了 main 函数,但如果您没有保存 .cpp 文件并尝试编译它也会出现相同的错误。因此请确保您已成功保存 .cpp 文件,然后编译并运行您的代码.

Hope this will help since I have faced similar issue and I spent around hours to figure it out , Thanks希望这会有所帮助,因为我遇到了类似的问题,我花了大约几个小时来弄清楚,谢谢

  1. The main() function is missing.缺少main()函数。
  2. Save as this code as some new file.将此代码另存为一些新文件。 Again run to compile the code.再次运行以编译代码。
  3. Check the PATH environment variable.检查PATH环境变量。

you have to save the file first>> Ctrl + s你必须先保存文件>> Ctrl + s

In VS Code, this can happen when you haven't saved your code.在 VS Code 中,当您尚未保存代码时可能会发生这种情况。 Click Ctrl + s to save the code and then run the program again.单击Ctrl + s保存代码,然后再次运行程序。

Or to make this happen automatically, go to Settings and search for "save".或者要自动执行此操作,请转到“设置”并搜索“保存”。 Scroll down and search for "Whether to save the current file before running" and enable it.向下滚动并搜索“运行前是否保存当前文件”并启用它。

main(int argc,char **argv)替换main() ,它对我main(int argc,char **argv)

If your already checked all the others reasons如果您已经检查了所有其他原因

I also got this message and it turned out that I accidentally placed my main() inside a namespace.我也收到了这条消息,结果证明我不小心将我的 main() 放在了命名空间中。 So it was hidden for global access所以它被隐藏以供全球访问

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

相关问题 未定义对“ 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) collect2.exe:错误:ld返回1退出状态 - collect2.exe: error: ld returned 1 exit status collect2.exe:错误:ld在Eclipse CDT中返回了1个退出状态 - collect2.exe: error: ld returned 1 exit status in eclipse cdt dev-cpp \\ collect2.exe [错误] ld返回1退出状态编译器指出什么错误? - dev-cpp\collect2.exe [Error] ld returned 1 exit status What error is the compiler pointing out? 获取错误代码:collect2.exe:错误:ld 返回 1 退出状态 - Getting the error code: collect2.exe: error: ld returned 1 exit status 为什么“collect2.exe:错误:ld 返回 1 退出状态”不断出现? - Why does the "collect2.exe: error: ld returned 1 exit status" keep coming? Gradle未定义引用`WinMain @ 16'错误 - Gradle undefined reference to `WinMain@16' error 错误对“ WinMain @ 16”的未定义引用 - Error Undefined reference to 'WinMain@16' Qt 5.2.1错误“ collect2.exe:Id返回1退出状态” - Error “collect2.exe: Id returned 1 exit status” with Qt 5.2.1 未定义对“ main” collect2的引用:错误:ld返回1退出状态 - undefined reference to `main' collect2: error: ld returned 1 exit status
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM