How to use vcpkg with clion?
已完成
It seems vcpkg is a very simple to use solution for incorporation c++ libraries.
How can you use it in combination with clion?
I've been trying to figure out how to incorporate external libraries in my project for a while now, but it seems every other existing method is library specific.
请先登录再写评论。
Anna Falevskaya you must be kidding! It's a shame variables are not supported!
Hello Anna,
I would like to bring an answer to Yoav's question, and raise a related one, which seems to be more complex.
How to use VCPKG with CLion
What Yoav tried to say is this: VCPKG provides a .cmake file to be used during configuration process, so that CMake can correctly recognize the needed libraries' paths. A good advice of its usage with CLion's cmake was found here ( https://github.com/Microsoft/vcpkg/issues/3572 ):
-DCMAKE_TOOLCHAIN_FILE=<path_to_vcpkg>/scripts/buildsystems/vcpkg.cmake
A no-usability case for VCPKG in CLion
However, when I use the aforementioned setup, the automatic configuration step which parses the CMakeLists.txt freezes at the point of "checking the working C compiler":
This does not progress; it does not un-freeze even after some time. It seems stuck on some parsing sub-routine.
To be clear, we speak here of the following configuration:
My project uses many libraries, managed by VCPKG, and the toolchain "CMake+VCPKG+MSVC" runs very well outside of CLion. Therefore, this seems to be a problem of a toolchain "CLion+VCPKG+MSVC" (hence the warning "experimental support" :) )
Anna Falevskaya I followed the tutorial. However, I got stuck at the step of installing the library (I tried raylib/boost/gtest) all of them same error:
I also tried to use x64-windows instead of the default one but also didn't work. I don't have any Visual Studio CMake Tool, and I don't want to install it. The article also doesn't mention anything about VS so I'm assuming it should work without it?
Hi, Yoav!
Just in case: in general external libraries should be included into a project using find_package and target_link_libraries CMake commands. We have a tutorial in our web help (here).
but vcpkg also installs the library and all its dependencies automatically...
In any case, I looked at the help page you linked to and tried to use the boost-assert library based on the information there.
I get the following error message:
"C:\Program Files\JetBrains\CLion 2017.2.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug5 -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" "C:\Users\yoavpol.WISMAIN\Dropbox\PhD\A - Project - C++\Codes\MD Box Clion"
CMake Error at C:/vcpkg/vcpkg-master/scripts/buildsystems/vcpkg.cmake:53 (message):
Unable to determine target architecture.
Call Stack (most recent call first):
C:/Program Files/JetBrains/CLion 2017.2.3/bin/cmake/share/cmake-3.8/Modules/CMakeDetermineSystem.cmake:88 (include)
CMakeLists.txt:2 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Would really appreciate some help with this. I'm starting to consider switching to Visual C++ just for the simple inclusion of libraries via vcpkg.
Could you please describe in more details what you've done?
In order to use Boost in your CMake project you need to have Boost libraries installed and to add smth similar to the following in your CMakeLists.txt:
@Viachaslau, thanks a lot for the clarification!
Unfortunately, I didn't managed to reproduce the issue on my side (CLion 2018.2.4, Windows 10, MSVC toolchain, bundled CMake). I installed vcpkg, installed Boost using it, added -DCMAKE_TOOLCHAIN_FILE=<path_to_vcpkg>/scripts/buildsystems/vcpkg.cmake to the CMake profile (File -> Settings -> Build, Execution, Deployment -> CMake), added lines about Boost to my CMakeLists.txt and the CMake project was loaded successfully:
Do you have any threadDump* folders in the logs folder (Help | Show Log in ...)? If yes, please send them to clion-support at jetbrains.com.
In case of this message, or any similar issue that makes it look that vcpkg is not being used at all, vcpkg will list the underlying issue in vcpkg-manifest-install-out.log and/or vcpkg-manifest-install-err.log.
In my case, 9/10 times it was something wrong with the portfile or my vcpkg.json manifest file.
Anna Falevskaya
If I set "CMake options" as follows -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
the $HOME variable is not recognized and results in
Could not find toolchain file: $HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
Call Stack (most recent call first):
It's ricidulous I can't use $HOME variable. Is there any workaround except pasting the full path?
I don't see what the big deal is about not using the "$HOME" variable... do people not know their own home directory? if you have to go in and copy/paste a directory path for something to work.. then it's not much more work to just add a few extra letters to your line..
I think it works beautifully.. Ty JB team and Kitware team for making this process so much easier. and scalable
Catujo please comment or upvote https://youtrack.jetbrains.com/issue/CPP-23439/CMake-options-does-not-expand-environment-variable.
I had to change to VSC cuz twas easier .. geez
Hi all!
We've just released the first CLion 2023.1 build which includes support for vcpkg in CLion. More info - https://blog.jetbrains.com/clion/2023/01/support-for-vcpkg-in-clion/. Feel free to give it a try!
Khiem06072007 please share the screenshot of your toolchains (`File | Settings | Build, Execution, Deployment | Toolchains`)
I get this error when using VCPKG (with the VCPKG Clion plugin) in "Manifest Mode"
```
Tobi, according to the error, "builtin-baseline" is not specified in your vcpkg.json file (located in C:\project):
You need to set "builtin-baseline" if you want to use "version>=".
For more information please see https://learn.microsoft.com/en-us/vcpkg/users/versioning#baselines:
Anna Falevskaya Thanks for the tip, sorry I completely glossed over the baseline part - and was focused on the CMAKE_COMPILER errors (suspecting the Clion Toolchain broke).
El unfortunately, for now it's not possible to use environment variables in CMake options. Feel free to comment or upvote https://youtrack.jetbrains.com/issue/CPP-23439/CMake-options-does-not-expand-environment-variable. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.