microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 450 forks source link

[Scan of Kits] only detected c89-gcc on Ubuntu 22.04 LTS #2556

Closed Demonese closed 3 months ago

Demonese commented 2 years ago

Brief Issue Summary

This problem prevents me from compiling the code with C17 (because of c89-gcc).

System: Ubuntu 22.04 LTS

Result of [Scan of Kits]:

[proc] Executing command: /usr/bin/c89-gcc -v
[proc] Executing command: /usr/bin/c99-gcc -v
[proc] Executing command: /usr/bin/gcc -v
[proc] Executing command: /usr/bin/gcc-11 -v
[proc] Executing command: /usr/bin/x86_64-linux-gnu-gcc -v
[proc] Executing command: /usr/bin/x86_64-linux-gnu-gcc-11 -v
[proc] Executing command: /bin/c89-gcc -v
[proc] Executing command: /bin/c99-gcc -v
[proc] Executing command: /bin/gcc -v
[proc] Executing command: /bin/gcc-11 -v
[proc] Executing command: /bin/x86_64-linux-gnu-gcc -v
[proc] Executing command: /bin/x86_64-linux-gnu-gcc-11 -v
[proc] Executing command: /bin/x86_64-linux-gnu-gcc -v
[proc] Executing command: /bin/x86_64-linux-gnu-gcc -v
[proc] Executing command: /bin/gcc -v
[proc] Executing command: /bin/gcc -v
[proc] Executing command: /bin/c99-gcc -v
[proc] Executing command: /bin/c89-gcc -v
[proc] Executing command: /usr/bin/x86_64-linux-gnu-gcc -v
[proc] Executing command: /usr/bin/x86_64-linux-gnu-gcc -v
[proc] Executing command: /usr/bin/gcc -v
[proc] Executing command: /usr/bin/gcc -v
[proc] Executing command: /usr/bin/c99-gcc -v
[proc] Executing command: /usr/bin/c89-gcc -v
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Found Kit: GCC 11.2.0 x86_64-linux-gnu
[kit] Successfully loaded 1 kits from /home/user/.local/share/CMakeTools/cmake-tools-kits.json

Result of CMakeTools/cmake-tools-kits.json

[
  {
    "name": "GCC 11.2.0 x86_64-linux-gnu",
    "compilers": {
      "C": "/usr/bin/c89-gcc"
    }
  }
]

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.67.1",
  "cmtVersion": "1.10.5",
  "configurations": [
    {
      "folder": "/home/user/Project/HelloWindow",
      "cmakeVersion": "3.22.1",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": false,
      "compilers": {
        "C": "/usr/bin/c89-gcc"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///home/user/Project/HelloWindow/main.c"
    ],
    "responses": [
      {
        "uri": "file:///home/user/Project/HelloWindow/main.c",
        "configuration": {
          "defines": [],
          "standard": "c17",
          "includePath": [],
          "compilerPath": "/usr/bin/c89-gcc",
          "compilerArgs": [
            "-g",
            "-std=c17"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "main",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

No response

Additional Information

I only install the latest stable version of gcc:

****@***:~/Project/HelloWindow$ apt list --installed *gcc*
Listing... Done
gcc-11-base/jammy,now 11.2.0-19ubuntu1 amd64 [installed,automatic]
gcc-11/jammy,now 11.2.0-19ubuntu1 amd64 [installed,automatic]
gcc-12-base/jammy,now 12-20220319-1ubuntu1 amd64 [installed,automatic]
gcc/jammy,now 4:11.2.0-1ubuntu1 amd64 [installed]
libgcc-11-dev/jammy,now 11.2.0-19ubuntu1 amd64 [installed,automatic]
libgcc-s1/jammy,now 12-20220319-1ubuntu1 amd64 [installed,automatic]
elahehrashedi commented 2 years ago

Thank you for reporting this issue. As a quick fix, you can edit your local kit using this command: "Edit User-Local CMake Kits" in which you can change the path to the compiler.

Demonese commented 2 years ago

As a quick fix, you can edit your local kit using this command: "Edit User-Local CMake Kits" in which you can change the path to the compiler.

My solution is edit CMakeTools/cmake-tools-kits.json file manually and avoid clicking the scan button until the problem is fixed.

aviborg commented 1 year ago

Got this issue too on a clean Ubuntu 22.04 install in a VirtualBox. Simply installing g++ with sudo apt install -y g++ seems to fix the issue for me.

gcampbell-msft commented 3 months ago

@aviborg Thanks for the solution, this is the correct fix for this issue, the tools need to be installed. Thanks!

diekleinekuh commented 2 weeks ago

@aviborg Thanks for the solution, this is the correct fix for this issue, the tools need to be installed. Thanks!

I think this assessment isn't correct. I ran into the same issue with a frsh install of Ubuntu 24.04 (in wsl). Then I did: sudo apt install cmake This will pull in gcc but only as a C compiler. The C compiler is working fine.

When lauching vscode with vscode-cmake-tools installed and scanning for kits the extension comes up with:

[
  {
    "name": "GCC 13.2.0 x86_64-linux-gnu",
    "compilers": {
      "C": "/usr/bin/c89-gcc"
    },
    "isTrusted": true
  }
]

The problem is that /usr/bin/c89-gcc is just a shell wrapper around gcc that automatically applies -std=c89. This will give you a C compiler that doesn't accept other flags like -std=c11 or -std=gnu17. So it is kinda crippled and will fail if a cmake script requests a higher C standard version.

While installing g++ is a workaround it should NOT be required and doesn't seem to be the correct solution to me. Why would you require users to install a C++ compiler if they only require C. This isn't a requirement that cmake introduces as it will work perfectly fine if the project in CMakeLists.txt specifies C as a language like this: project(myproject C)

IMHO the code in vscode-cmake-tools should not pick up those shell warppers that hard code certain C standards as this isn't what cmake want's to see as the compiler executable. I think the code searching for kits should either ignore the shell wrappers or list them as separate kits.

Could you please reopen this issue?