final link failed: Invalid argument when including windows.h

為{幸葍}努か 提交于 2020-01-04 04:06:46

问题


I have set up MinGW and Eclipse with CDT for C++ developing on Windows. Everything works great until I #include <windows.h>. As soon as I do that, I get the linker error message c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid argument whereby the path at the beginning resolves to C:/MinGW/mingw32/bin/ld.exe.

I have no idea what the error message tries to tell me... so please help me to decrypt it.


回答1:


Since I actually don't agree to Lol4t0's opinion that this is too localized here is the ugly answer: Reinstalling G++ solved the problem.

I think the problem also could have been that I maybe forgot to install one of the parts listed here (where I got it from) for the first time... but now I recognize the link is completely deprecated (2005). So one should use another anyway.




回答2:


Perhaps you are missing one of the linking parameters on the command line.

E.g., you might want to add the -lgdi32 -lkernel32 -luser32 if you use any of WinAPI functions declared in <windows.h>

Since you are getting errors in Eclipse, add these libraries (gdi32, kernel32, user32) here:

Project Proprerties -> C/C++ build -> Settings -> GCC Linker -> Libraries -> "add the library"

(this is taken from eclipse cdt command line input)



来源:https://stackoverflow.com/questions/10367413/final-link-failed-invalid-argument-when-including-windows-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!