Matteo B.
Matteo B.

Reputation: 4064

final link failed: Invalid argument when including windows.h

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.

Upvotes: 3

Views: 3291

Answers (2)

Sergey K.
Sergey K.

Reputation: 25386

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)

Upvotes: 0

Matteo B.
Matteo B.

Reputation: 4064

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.

Upvotes: 1

Related Questions