Using libs from vscpkg in CLion.

Answered

I try to use external modules from vscpkg for my C project and all seems so unintuitive I dont know how to do it.

I have tried also add_libraries() and it cant find it too.

 

cmakelists.txt :

cmake_minimum_required(VERSION 3.14)
project(SSHwinx32 C)

set(CMAKE_C_STANDARD 11)

find_package(libssh CONFIG REQUIRED)
target_link_libraries(main PRIVATE ${libssh.h)
target_include_directories(main PRIVATE ${C/Users/ansga/vcpkg/installed/x86-windows/include/libssh})

add_executable(SSHwinx32 main.c)

 

output: 

CMake Error at CMakeLists.txt:6 (find_package):
Could not find a package configuration file provided by "libssh" with any
of the following names:

libsshConfig.cmake
libssh-config.cmake

Add the installation prefix of "libssh" to CMAKE_PREFIX_PATH or set
"libssh_DIR" to a directory containing one of the above files. If "libssh"
provides a separate development package or SDK, be sure it has been
installed.


 

0
2 comments

Hello!

1. As far as I know, VCPKG provides a .cmake file to be used during configuration process, so that CMake can correctly recognize the needed libraries' paths. So you need to add -DCMAKE_TOOLCHAIN_FILE=<path_to_vcpkg>/scripts/buildsystems/vcpkg.cmake to the CMake profile (File -> Settings -> Build, Execution, Deployment -> CMake).

2. You need first create a target and then link libraries to the target. It should look similar to the following:

cmake_minimum_required(VERSION 3.14)
project(SSHwinx32 C)

set(CMAKE_C_STANDARD 11)

add_executable(SSHwinx32 main.c)


find_package(libssh REQUIRED)
target_link_libraries(main PRIVATE ${LIBSSH_LIBRARIES})
target_include_directories(main PRIVATE ${LIBSSH_INCLUDE_DIRS})
2

Very helpful. Thank you.

0

Please sign in to leave a comment.