CLion and valgrind on Windows
I am running CLion under Windows 10 and would like to use valgrind.
I have installed WSL (windows subsystem for Linux) and installed valgrind. It works fine from the command line under "ubuntu WSL"
https://www.jetbrains.com/help/clion/memory-profiling-with-valgrind.html seems to imply that I should be able to point CLion to the valgrind executable and have it work seamlessly, but that is not possible. CLion is running under Windows, so the executables it has produced are for Windows. valgrind is in ubuntu WSL, so it is a linux executable. Calling valgrind on the windows executable does not make sense. Plus, the WSL files are not easily accessible from Windows since there is a high chance of corrupting them if you edit a file using Windows tools.
I see several ways forward, but need guidance on which is the best alternative:
1) Open an ubuntu shell, copy the source files to WSL. Recompile the program using ubuntu's g++ to create a linux executable and then run valgrind on it.
2) Run CLion in "ubuntu WSL", so that everything is running in linux. This would mean running a Linux version of CLion whenever I need to use valgrind and using the Windows version all other times.
3) Figure out how to compile valgrind under Msys2 which has ported many unix programs to Windows. valgrind would then be a Windows exectable and work with CLion. Not sure this is possible. A lot of what I have read suggests valgrind is not a trivial port and unlikely to be included in Windows anytime soon.
4) Write a Windows script to do option #1 above, but unclear how the script would integrate with CLion
5) Find an alternative to valgrind that works under Windows.
6) Sell my Windows computer and go back to my Mac ;-) (back to linux is not option, that ship has sailed for personal computer)
7) Some other brilliant option that somebody from here will come up with!
Thanks,
Y
请先登录再写评论。
Hello!
>CLion is running under Windows, so the executables it has produced are for Windows.
When you use a WSL toolchain in CLion, the project is built and run on "ubuntu WSL". So as Valgrind.
If you have a WSL toolchain configured in CLion and you're using it, you don't need to copy the source files to WSL, CLion will do it for you.
Please see https://www.jetbrains.com/help/clion/how-to-use-wsl-development-environment-in-clion.html and https://blog.jetbrains.com/clion/2018/01/clion-and-linux-toolchain-on-windows-are-now-friends/.
Brilliant! I am glad that the good folks at IntelliJ wrote the script to connect to the ubuntu WSL via ssh and run cmake rather than my crude scripting.
One problem I encountered was that CLion created a file C:\Users\myusername\bin\valgrind.bat and the CLion configuration for valgrind pointed at this file. The script did not work for me. The script looks like it should be called from Windows, but CLion internally calls it from the ubuntu WSL instead.
I wrote an alternative script called valgrind-ubuntu.sh using Unix line endings with the contents below which works with CLion.
when using WSL toolchain, valgrind should point at C:\Users\myusername\bin\valgrind-ubuntu.sh with the contents below
==============================
#!/bin/bash
echo "Starting valgring-ubuntu"
cmake .
make .
valgrind $*
echo "Ending valgring-ubuntu"
==============================
Actually, the procedure of using Valgrind on WSL in CLion is the following:
When you have WSL toolchains configured in CLion, you can see the Valgrind settings in Settings | Build, Execution, Deployment. And you need simply provide a path to the Valgrind executable (smth similar to /usr/bin/valgrind) in Valgrind settings in CLion. That's all. After that you will be able to use Valgrind (installed on WSL) in CLion (installed on Windows).
More info: https://blog.jetbrains.com/clion/2018/02/clion-2018-1-eap-valgrind-wsl-partial-commits-cpp-support/.