2

I installed gcc 11 using homebrew on my machine (linux 20.04). And It is not running on vscode as it shows

as: unrecognized option '--gdwarf-5'

I'm not sure if it's a path problem or not. Cause when I installed brew it told me

Warning: /home/linuxbrew/.linuxbrew/bin/ is not in your PATH.

to fix this it suggested these three commands

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /home/hasib/.profile
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/hasib/.profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

So, I did those. And I don't know if this screwed up the PATH. I'm kinda new to Linux so confused. Just wanna run gcc-11 on vs.

this is my tasks.json file :

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: g++ build active file",
        "command": "/usr/bin/g++",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "Build with GCC 11.3.0",
        "command": "/home/linuxbrew/.linuxbrew/bin/g++-11",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "-std=c++20",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "compiler: /home/linuxbrew/.linuxbrew/bin/g++-11"
    },
    {
        "type": "cppbuild",
        "label": "C/C++: g++-10 build active file",
        "command": "/usr/bin/g++-10",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "compiler: /usr/bin/g++-10"
    }
],
"version": "2.0.0"
}

launch.json :

{

"version": "0.2.0",
"configurations": []
}

Output of gcc-11 --version :

gcc-11 (Homebrew GCC 11.3.0) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Output of gdb --version :

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Hasib Al Fuad
  • 29
  • 1
  • 4
  • 1
    Shouldn't it just be a single dash in the option like `-g`? – dewaffled Oct 08 '22 at 22:48
  • 1
    Worth noting that (linux 20.04) isn't really a thing. You likely mean Ubuntu judging by the version number. Also, new to Linux, and installed a years-old distribution? I think gcc 11 would be natively available if you were using a current version. The cherry on top is that man page clearly shows that you should only use a single dash: `-gdwarf 5`, but just use `-g` anyway unless you absolutely know you need something else. – sweenish Oct 08 '22 at 23:02
  • What is calling gcc with --dwarf-5 option? That is not vscode. – Something Something Oct 09 '22 at 00:18
  • yes I mean ubuntu 20.04 – Hasib Al Fuad Oct 09 '22 at 06:54
  • @sweenish I donno where it is getting the -gdwarf from. In the task.json file it says "-g" – Hasib Al Fuad Oct 09 '22 at 06:57
  • @HenriqueBucher That is what I don't understand. but I'm running it on vscode – Hasib Al Fuad Oct 09 '22 at 07:01
  • Obviously, there isn't sufficient information provided. At a minimum, we'd need to see your `tasks.json` and `launch.json`. Any pertinent extensions that are installed. The output of commands like `g++-11 --version` and `gdb --version`, etc. – sweenish Oct 09 '22 at 08:23
  • @sweenish updated in the post. – Hasib Al Fuad Oct 09 '22 at 13:44
  • Since it's the `as` executable that's throwing the error, you need to check the binutils version, it's probably too old for dwarf-5. – ssbssa Oct 10 '22 at 10:30

1 Answers1

4

as (the GNU assembler) is part of the binutils package. You need to install a recent version of binutils where as has support for the --gdwarf-5 flag and ensure that it is the one used by gcc-11.

You can check whether the as in your $PATH has support for that flag by running

as --help | grep gdwarf

If it does, it return contain the line:

--gdwarf-<N>            generate DWARF<N> debugging information. 2 <= <N> <= 5

If that is not returned, try installing the latest version of binutils via linuxbrew (and, just in case you haven't, restart your desktop session to ensure that all your terminals and vscode get the updates to $PATH, etc.)

Hisham H M
  • 6,398
  • 1
  • 29
  • 30
  • Right to the point, thank you. `brew` seems to install `binutils` as keg-only, which means it will not create the appropriate symbolic links; thus other existing `binutils` versions will prevail. Adding `home/linuxbrew/.linuxbrew/Cellar/binutils//bin` to the `PATH` or specifying the correct tool-chain should do the trick. – Miguel Dec 22 '22 at 12:09
  • 1
    I was able to install `as` with linuxbrew using the command `brew install binutils`. After installing I had to run `brew link binutils --force` to add `as` to my path. Brew doesn't link binutils by default. – jwenz723 Jan 20 '23 at 23:15