vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Linux: Add support for snaps of CMake

Open Zingam opened this issue 5 years ago • 24 comments

I have just installed Ubuntu 19.10 and used the Software installer application to install Visual Studio Code and CMake 3.15. I cloned my repository from GitHub and whenever I try to call CMake configure in Visual Studio code I get an error message: Bad CMake executable /snap/bin/cmake. CMake seems to run fine in a terminal.

VS Code/CMake extension used to run just fine out-of-the-box in previous version of Ubuntu.

When I try to enter the path manually I get error messages like these:

[rollbar] Unhandled exception: Unhandled Promise rejection: configure TypeError: Cannot read property 'on' of undefined {} [rollbar] Unhandled exception: Error during CMake upgrade TypeError: Cannot read property 'on' of undefined {"version":"3.13.2","linuxURL":"https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2-Linux-x86_64.sh","windowsURL":"https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2-win64-x64.msi"}

Actually /snap/bin/cmake is not an executable but a link if I recall correctly.

Zingam avatar Oct 19 '19 08:10 Zingam

A link should be ok. In your case the extension is running /snap/bin/cmake --version and inspecting the output to check if the executable is ok. Can you run that command and let me know what it prints out in your terminal?

The "unhandled exception" error is unrelated to this and should be gone in 1.2.0 (unreleased).

bobbrow avatar Oct 21 '19 15:10 bobbrow

Ubuntu Terminal:

~$ /snap/bin/cmake --version cmake version 3.15.4

CMake` suite maintained and supported by Kitware (kitware.com/cmake).

VSCode Terminal:

~/Projects/GitHub/GunBox/GunBox$ ~$ /snap/bin/cmake --version ~$: command not found ~/Projects/GitHub/GunBox/GunBox$ cmake version 3.15.4 CMake Error: The source directory "/home/hristo/Projects/GitHub/GunBox/GunBox/3.15.4" does not exist. Specify --help for usage, or press the help button on the CMake GUI. /Projects/GitHub/GunBox/GunBox$ ~/Projects/GitHub/GunBox/GunBox$ CMake suite maintained and supported by Kitware (kitware.com/cmake). bash: syntax error near unexpected token `(' ~/Projects/GitHub/GunBox/GunBox$

I removed the PC name

Zingam avatar Oct 21 '19 20:10 Zingam

This command also appears to execute properly: /snap/bin/cmake -E server --experimental

Zingam avatar Oct 23 '19 03:10 Zingam

@bobbrow Will version 1.2 be released soon?

Zingam avatar Oct 23 '19 03:10 Zingam

Yes. Should be early next week. We're doing some final testing.

bobbrow avatar Oct 25 '19 19:10 bobbrow

OK. Thanks! I'll wait to see how version 1.2 will behave as the currently released doesn't work for me neither on latest Ubuntu nor Windows with the latest MSVC, CMake, GCC, etc. All of which worked before.

Zingam avatar Oct 28 '19 04:10 Zingam

It works when you use /snap/cmake/current/bin/cmake as CMake Path. All snap executables seem to be just symbolic links to /usr/bin/snap, and that seems to work fine when called from a terminal but apparently not from the CMake extension in VSCode ...

hheld avatar Nov 01 '19 08:11 hheld

@hheld Thank you for the advice. I'll try that. I tried setting this manually before but maybe I didn't set the proper path.

Zingam avatar Nov 01 '19 10:11 Zingam

There are two entries related to CMake Path. Which one is the correct one:

Cmake: Cmake Path Name/path of the CMake executable to use cmake Cmake: Ctest Path Path to CTest executable. If null, will be inference from cmake.cmakePath (recommended to leave null) Cmake: Cmake Path The path to CMake generator executable

@hheld Setting /snap/cmake/current/bin/cmake did the job!

Screenshot from 2019-11-01 13-12-05 Thank you!

I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

Zingam avatar Nov 01 '19 11:11 Zingam

@bobbrow Maybe this issue's title should be changed and filed as a bug: "CMake Tools" don't work with symbolic links on Linux?

Zingam avatar Nov 01 '19 11:11 Zingam

I don't think this issue has anything to do with symbolic links. I don't really know the mechanics of how snap apps work, but I guess something must transform a call to /snap/bin/cmake to something like snap run cmake -- and I guess this doesn't happen when called from the VSCode extension. The link simply points to /usr/bin/snap and this isn't cmake.

hheld avatar Nov 01 '19 13:11 hheld

In regard to this: https://github.com/microsoft/vscode-cmake-tools/issues/685#issuecomment-557335459

I'm also experiencing this issue on Ubuntu:

I installed vscode/cmake from snap packages

$ cmake --version cmake version 3.16.0-rc4 CMake suite maintained and supported by Kitware (kitware.com/cmake).

But I got this error from the vscode extension:

Bad CMake executable "/snap/bin/cmake". Is it installed or settings contain the correct path (cmake.cmakePath)?

I checked my path

echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

I checked my cmake

$ which cmake /snap/bin/cmake

The story so far...

The snap/bin/cmake links points to the snap application.

/snap/bin$ ls -l
total 0
lrwxrwxrwx 1 root root 12 ное  1 13:02 ccmake -> cmake.ccmake
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.ccmake -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.cmake-gui -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.cpack -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.ctest -> /usr/bin/snap
lrwxrwxrwx 1 root root 15 ное  1 13:02 cmake-gui -> cmake.cmake-gui
lrwxrwxrwx 1 root root 13 ное 17 08:34 code -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 17 08:34 code.url-handler -> /usr/bin/snap
lrwxrwxrwx 1 root root 11 ное  1 13:02 cpack -> cmake.cpack
lrwxrwxrwx 1 root root 11 ное  1 13:02 ctest -> cmake.ctest
lrwxrwxrwx 1 root root 13 ное  1 13:15 gimp -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 gnome-calculator -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 17 08:34 gnome-characters -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 окт 19 09:45 gnome-logs -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.npm -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.npx -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.yarn -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.yarnpkg -> /usr/bin/snap
lrwxrwxrwx 1 root root  8 ное 22 09:04 npm -> node.npm
lrwxrwxrwx 1 root root  8 ное 22 09:04 npx -> node.npx
lrwxrwxrwx 1 root root  9 ное 22 09:04 yarn -> node.yarn
lrwxrwxrwx 1 root root 12 ное 22 09:04 yarnpkg -> node.yarnpkg

snap list can be used to check for an installed cmake package.

/snap/bin$ snap list
Name                Version                     Rev   Tracking  Publisher     Notes
cmake               3.15.5                      148   stable    crascit✓      classic
code                8795a988                    20    stable    vscode✓       classic
core                16-2.42.1                   8039  stable    canonical✓    core
core18              20191030                    1265  stable    canonical✓    base
gimp                2.10.12                     227   stable    snapcrafters  -
gnome-3-28-1804     3.28.0-16-g27c9498.27c9498  110   stable/…  canonical✓    -
gnome-calculator    3.34.1+git1.d34dc842        544   stable/…  canonical✓    -
gnome-characters    v3.32.1+git2.3367201        367   stable/…  canonical✓    -
gnome-logs          3.34.0                      81    stable/…  canonical✓    -
gtk-common-themes   0.1-25-gcc83164             1353  stable/…  canonical✓    -
gtk2-common-themes  0.1                         5     stable    canonical✓    -
node                13.2.0                      2559  13        nodesource✓   classic

snap run cmake to execute the snap package.

/snap/bin$ snap run cmake
Usage

  cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>
  cmake [options] -S <path-to-source> -B <path-to-build>

Specify a source directory to (re-)generate a build system for it in the
current working directory.  Specify an existing build directory to
re-generate its build system.

Run 'cmake --help' for more information.

cmake.cmakePath

Cmake: Cmake Path Name/path of the CMake executable to use. /snap/cmake/current/bin/cmake "cmake.cmakePath": "/snap/cmake/current/bin/cmake"

Cmake: Cmake Path The path to CMake generator executable "cmake.cmakePath": "/snap/cmake/current/bin/cmake"

I wonder how did the extension decide to use the path /snap/bin/cmake as a cmake.cmakePath setting?

Zingam avatar Nov 22 '19 07:11 Zingam

There are two entries related to CMake Path. Which one is the correct one:

Cmake: Cmake Path Name/path of the CMake executable to use cmake Cmake: Ctest Path Path to CTest executable. If null, will be inference from cmake.cmakePath (recommended to leave null) Cmake: Cmake Path The path to CMake generator executable

@hheld Setting /snap/cmake/current/bin/cmake did the job!

Screenshot from 2019-11-01 13-12-05 Thank you!

I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

This fixed for me

pietromezzadri avatar Oct 15 '20 11:10 pietromezzadri

There are two entries related to CMake Path. Which one is the correct one:

Cmake: Cmake Path Name/path of the CMake executable to use cmake Cmake: Ctest Path Path to CTest executable. If null, will be inference from cmake.cmakePath (recommended to leave null) Cmake: Cmake Path The path to CMake generator executable

@hheld Setting /snap/cmake/current/bin/cmake did the job! Screenshot from 2019-11-01 13-12-05 Thank you! I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

This fixed for me

This also worked for me. Thank you much!

cemlyn007 avatar Dec 14 '20 12:12 cemlyn007

I don't think this issue has anything to do with symbolic links. I don't really know the mechanics of how snap apps work, but I guess something must transform a call to /snap/bin/cmake to something like snap run cmake -- and I guess this doesn't happen when called from the VSCode extension. The link simply points to /usr/bin/snap and this isn't cmake.

@hheld snap uses argv[0] for transforming the call to the "real" cmake. My best educated guess is some code in the VS plugin fully resolves the symlink and invoke it, so argv[0] is lost in this process

mosdav avatar Dec 15 '20 23:12 mosdav

@hheld Setting /snap/cmake/current/bin/cmake did the job! Thank you! I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

This fixed for me

This also worked for me. Thank you much!

This also works for me. Many thanks!

But it would be nice if this issue can really be fixed (i.e. /snap/bin/cmake should ideally be fine).

TianyiShi2001 avatar Feb 08 '21 21:02 TianyiShi2001

@TianyiShi2001 Yesterday I setup a new Linux development environment and it is still The Way. I had the intention to fix this but Microsoft stopped reviewing and merging new PRs for nearly a year and I also stopped using VSCode, so I lost the motivation. Now I am back to using it but I doubt that I'll have the time. I think implementing this functionality would be relatively easy. Typescript is easy. It will require some refactoring how CMake is detected though. Why not try to do it yourself? That would be a fun little project.

Unfortunately even the simplest features require a lot of iterations and thus a lot of time.

Zingam avatar Feb 09 '21 05:02 Zingam

same problem

mumin16 avatar Apr 25 '21 22:04 mumin16

The same on Ubuntu 20.04.

$ which cmake
/snap/bin/cmake

The /snap/bin/cmake is link:

$ readlink -f /snap/bin/cmake
/usr/bin/snap

CMake works by that link:

$ /snap/bin/cmake --version
cmake version 3.20.2

but VS Code doesn't support it.

Solution is to use /snap/cmake/current/bin/cmake as @hheld suggested above :+1:

Dimon4eg avatar Apr 30 '21 22:04 Dimon4eg

Another solution:

$ sudo ln -s /snap/cmake/current/bin/cmake /user/bin/cmake

H-G-Hristov avatar Feb 10 '22 16:02 H-G-Hristov

It seems that @H-G-Hristov 's solution is more suitable for me.

$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake

First of all, my laptop has a dual-boot setup with both Windows and Kubuntu installed. Moreover, the vscode installations on both systems share a settings.json configuration file stored in the cloud.

If I adopt solution 1, by setting "cmake.cmakePath" to /snap/cmake/current/bin/cmake, I would need to manually adjust "cmake.cmakePath" every time I switch between the Windows and Kubuntu systems. This is because cmake-tools on Windows cannot locate the file /snap/cmake/current/bin/cmake.

On the other hand, if I adopt solution 2, by creating a new symbolic link /usr/bin/cmake to /snap/cmake/current/bin/cmake using ln -s, then I wouldn't need to make any additional modifications to "cmake.cmakePath" on Kubuntu. I would just let cmake-tools find cmake within the existing PATH environment variable. Since the priority of /usr/bin is higher than that of /snap/bin, it will preferentially find the symbolic link at /usr/bin/cmake, rather than /snap/bin/cmake.

Click to expand demo logs for solution 2
hwhsu1231@vb-kubuntu:~$ /snap/cmake/current/bin/cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake
[sudo] password for hwhsu1231: 
hwhsu1231@vb-kubuntu:~$ which -a cmake
/usr/bin/cmake
/bin/cmake
/snap/bin/cmake
hwhsu1231@vb-kubuntu:~$ which cmake
/usr/bin/cmake
hwhsu1231@vb-kubuntu:~$ cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ echo $PATH
/home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts

hwhsu1231 avatar Dec 29 '23 11:12 hwhsu1231

Fix for me change cmakePath from: cmake to: /snap/cmake/1366/bin

Neels99 avatar Mar 20 '24 14:03 Neels99

It seems that @H-G-Hristov 's solution is more suitable for me.

$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake

First of all, my laptop has a dual-boot setup with both Windows and Kubuntu installed. Moreover, the vscode installations on both systems share a settings.json configuration file stored in the cloud.

If I adopt solution 1, by setting "cmake.cmakePath" to /snap/cmake/current/bin/cmake, I would need to manually adjust "cmake.cmakePath" every time I switch between the Windows and Kubuntu systems. This is because cmake-tools on Windows cannot locate the file /snap/cmake/current/bin/cmake.

On the other hand, if I adopt solution 2, by creating a new symbolic link /usr/bin/cmake to /snap/cmake/current/bin/cmake using ln -s, then I wouldn't need to make any additional modifications to "cmake.cmakePath" on Kubuntu. I would just let cmake-tools find cmake within the existing PATH environment variable. Since the priority of /usr/bin is higher than that of /snap/bin, it will preferentially find the symbolic link at /usr/bin/cmake, rather than /snap/bin/cmake.

Click to expand demo logs for solution 2

hwhsu1231@vb-kubuntu:~$ /snap/cmake/current/bin/cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake
[sudo] password for hwhsu1231: 
hwhsu1231@vb-kubuntu:~$ which -a cmake
/usr/bin/cmake
/bin/cmake
/snap/bin/cmake
hwhsu1231@vb-kubuntu:~$ which cmake
/usr/bin/cmake
hwhsu1231@vb-kubuntu:~$ cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ echo $PATH
/home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts

wsl and windows use different settings.json

I use wsl and i can apply diff settings.json in wsl and windows I wonder if windows and kubuntu can hold diff settings.json like wsl and windows do. I have little knowledge about kubuntu, please forgive my misunderstandings

chanmaoganda avatar Jun 06 '24 03:06 chanmaoganda