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.

1

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).

0

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.

0

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:

find_package(Boost) 
IF (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries (my_target ${Boost_LIBRARIES})
endif()
0
Avatar
Permanently deleted user

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 ):

  1. Go to File -> Settings -> Build, Execution, Deployment -> CMake
  2. Choose one profile, and then find "CMake Options".
  3. Insert value to the option: -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":

"C:\Program Files\CMake\bin\cmake.exe"
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_TOOLCHAIN_FILE=D:/<some-path>/vcpkg/scripts/buildsystems/vcpkg.cmake
-G "CodeBlocks - NMake Makefiles" D:\<my-project>

-- The C compiler identification is MSVC 19.14.26431.0
-- The CXX compiler identification is MSVC 19.14.26431.0
-- Check for working C compiler: C:/Program Files (x86)/
Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe

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:

  1. Windows 7 x64
  2. Microsoft Visual Studio 2017 Build Tools
  3. cmake 3.* (either I use bundled version, 3.10 / 3.12, or the independently installed one, 3.11 - it is still the same problem)

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" :) )

1

@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.

0

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. 

0

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?

0

Anna Falevskaya you must be kidding! It's a shame variables are not supported!

2

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

0

I had to change to VSC cuz twas easier .. geez

0

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:

warning: Starting with the September 2023 release, the default triplet for vcpkg libraries will change from x86-windows to the detected host triplet (x64-windows). To resolve this message, add --triplet x86-windows to keep the same behavior.
Computing installation plan...
The following packages will be built and installed:
    gtest[core]:x86-windows -> 1.13.0
  * vcpkg-cmake[core]:x64-windows -> 2022-12-22
  * vcpkg-cmake-config[core]:x64-windows -> 2022-02-06#1
Additional packages (*) will be modified to complete this operation.
error: in triplet x64-windows: Unable to find a valid Visual Studio instance
Could not locate a complete Visual Studio instance

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? 

1

Khiem06072007 please share the screenshot of your toolchains (`File | Settings | Build, Execution, Deployment | Toolchains`)

0

I get this error when using VCPKG (with the VCPKG Clion plugin) in "Manifest Mode"

 

 

```

C:\Users\Tobi\AppData\Local\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/Tobi/AppData/Local/Programs/CLion/bin/ninja/win/x64/ninja.exe -G Ninja -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=C:\Users\Tobi\vcpkg\scripts\buildsystems\vcpkg.cmake -S C:\project -B C:\project\cmake-build-debug
-- Running vcpkg install
error: C:\project\vcpkg.json was rejected because it uses "version>=" and does not have a "builtin-baseline". This can be fixed by removing the uses of "version>=" or adding a "builtin-baseline".
See `vcpkg help versioning` for more information.
-- Running vcpkg install - failed
CMake Error at C:/Users/Tobi/vcpkg/scripts/buildsystems/vcpkg.cmake:899 (message):
vcpkg install failed. See logs for more information:
C:\project\cmake-build-debug\vcpkg-manifest-install.log
Call Stack (most recent call first):
C:/Users/Tobi/AppData/Local/Programs/CLion/bin/cmake/win/x64/share/cmake-3.26/Modules/CMakeDetermineSystem.cmake:148 (include)
CMakeLists.txt:8 (project)


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

[Failed to reload]
0

Tobi, according to the error, "builtin-baseline" is not specified in your vcpkg.json file (located in C:\project):

C:\project\vcpkg.json was rejected because it uses "version>=" and does not have a "builtin-baseline". This can be fixed by removing the uses of "version>=" or adding a "builtin-baseline".

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:

To add an initial "builtin-baseline", use vcpkg x-update-baseline --add-initial-baseline

0

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).

 

0

请先登录再写评论。