skeeto / w64devkit

Portable C and C++ Development Kit for x64 (and x86) Windows
The Unlicense
2.7k stars 185 forks source link

g++ -g not working in cmd.exe #32

Closed Dreamerxic closed 1 year ago

Dreamerxic commented 1 year ago

A command like:

~ $ g++ a.cpp -o a.exe -g

works properly in w64devkit.exe. But in cmd.exe, this command prints

> g++.exe a.cpp -o a.exe -g
as: unknown option -- gdwarf-5

In cmd.exe, commands like:

> g++.exe a.cpp -o a.exe 
> g++.exe a.cpp -o a.exe -g -S

works, and

> g++.exe a.cpp -o a.exe -g -c

doesn't.

I had never met such a problem with an old version w64devkit, I can't get more details from it. Hope the issue would be useful. Please tell me if I do anything wrong.

skeeto commented 1 year ago

This looks like you've got an old "as" early in your PATH which doesn't belong to w64devkit. Perhaps it's from an old, leftover MinGW installation that had added itself to your PATH. You wouldn't have noticed it in older w64devkit releases that only had GCC 10, which still defaulted to DWARF 4.

Check "which as" which should point at an "as.exe" inside w64devkit. Check "g++ -print-prog-name=as" to see what assembler GCC is using. Check PATH for anything suspicious like a MinGW install. Check the "edit environment variables for your account" and "edit the system environment variables" dialogs for anything suspicious. Check that you're calling the intended compiler with "which g++" and that it's using the correct linker using "g++ -print-prog-name=ld" and "which ld". The "--version" option for both "as" and "ld" should report Binutil 2.39.

I can confirm that a "hello world" C++ program compiles and works fine, even from cmd.exe, when using w64devkit on a fresh Windows installation, at least for XP, 7, 10, and 11.

(This issue was one of my motivations for w64devkit. With no installation, it won't contaminate your PATH or registry as a number of other tools do, including whatever is putting an as.exe in your PATH. Removal is just a matter of deleting the w64devkit directory.)

Dreamerxic commented 1 year ago

It seems that the old version w64devkit in PATH covered the new one. After removing the old PATH, command option -g in cmd.exe works correctly. Thanks.