syheliel
syheliel

Reputation: 181

Can't use vcpkg on linux

Here is my CMakelists.txt:

cmake_minimum_required(VERSION 3.0) 
SET(CMAKE_TOOLCHAIN_FILE "/home/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(test)

find_package(unofficial-sqlite3 CONFIG REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

I'm trying to use vcpkg through SET(CMAKE_TOOLCHAIN_FILE ${vcpkg_root}),but it seems that it doesn't work.Here is the error:

[cmake] CMake Error at CMakeLists.txt:5 (find_package):
[cmake]   Could not find a package configuration file provided by
[cmake]   "unofficial-sqlite3" with any of the following names:
[cmake] 
[cmake]     unofficial-sqlite3Config.cmake
[cmake]     unofficial-sqlite3-config.cmake

I have verify that unofficial-sqlite3-config.cmake does exists in

/home/xxx/vcpkg/packages/sqlite3_x64-linux/share/unofficial-sqlite3/unofficial-sqlite3-config.cmake

I'm using WSL and vscode as IDE, Now I have no idea how to fix it.

Upvotes: 1

Views: 1154

Answers (1)

Alex Reinking
Alex Reinking

Reputation: 19946

I could not reproduce your issue using the following basic CMakeLists.txt

cmake_minimum_required(VERSION 3.21)
project(test)

find_package(unofficial-sqlite3 REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

I installed sqlite3 via vcpkg install sqlite3 and ran the build via

$ echo 'int main() { return 0; }' > main.cpp
$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/build

As you can see, this worked flawlessly. I'm not sure whether setting your CMake policy level to the downright ancient 3.0 is what matters, or if you're using an old vcpkg checkout (I used the most recent commit at time of writing).

Upvotes: 1

Related Questions