Can't use vcpkg on linux - c++

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.

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

Related

CMake Error : Could NOT find Boost (missing: Boost_INCLUDE_DIR system thread regex iostreams)

Windows 10
Cmake version : 3.24.0
Boost version : 1.66.0
CLion version : 2022.1.3
Do you have any idea about how i can fix this ?
I found on other topics some answer but it didn't work for me.
C:\Users\33671\AppData\Local\JetBrains\CLion2022.1\cygwin_cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=/cygdrive/c/Program Files/JetBrains/CLion 2022.1.3/bin/ninja/cygwin/ninja.exe" -G Ninja -S /cygdrive/c/Users/33671/Desktop/main_program-master -B /cygdrive/c/Users/33671/Desktop/main_program-master/cmake-build-debug-cygwin
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.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++.exe - 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 - Success
-- Found Threads: TRUE
CMake Error at /cygdrive/c/Users/33671/AppData/Local/JetBrains/CLion2022.1/cygwin_cmake/share/cmake-3.22.3/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR system thread regex
iostreams)
Call Stack (most recent call first):
/cygdrive/c/Users/33671/AppData/Local/JetBrains/CLion2022.1/cygwin_cmake/share/cmake-3.22.3/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/cygdrive/c/Users/33671/AppData/Local/JetBrains/CLion2022.1/cygwin_cmake/share/cmake-3.22.3/Modules/FindBoost.cmake:2375 (find_package_handle_standard_args)
CMakeLists.txt:10 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "/cygdrive/c/Users/33671/Desktop/main_program-master/cmake-build-debug-cygwin/CMakeFiles/CMakeOutput.log".
[Finished]
Also my CMakeList.txt is like this :
cmake_minimum_required(VERSION 3.5)
project(test)
set(CMAKE_CXX_STANDARD 14)
SET(Boost_USE_STATIC_LIBS NO)
SET(Boost_USE_MULTITHREAD ON)
SET(CMAKE_PREFIX_PATH /lib/)
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread regex iostreams)# 1.66.0
IF(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ENDIF(Boost_FOUND)
SET(USED_LIBS ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_IOSTREAMS_LIBRARY})

Windows not able to find FLEX_LIBRARIES

When using this CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(project_c)
set(CMAKE_CXX_STANDARD 11)
set(project_name project_c)
find_package(BISON)
find_package(FLEX)
BISON_TARGET(parser parser.y ${CMAKE_SOURCE_DIR}/parser.cpp)
FLEX_TARGET(lexer lexer.l ${CMAKE_SOURCE_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(lexer parser)
add_executable(${project_name} ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS})
target_include_directories(${project_name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${project_name} ${FLEX_LIBRARIES})
CMake complains about
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FL_LIBRARY (ADVANCED)
linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c
I've tried to copy the winflex folder inside the project folder but that won't help anyway. This proposed solution isn't working.
This is the complete CMake log
"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\asant\workspace\CLionProjects\project_c
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found BISON: C:/Program Files (x86)/win_flex_bison-2.5.23/win_bison.exe (found version "3.7.1")
-- Found FLEX: C:/Program Files (x86)/win_flex_bison-2.5.23/win_flex.exe (found version "2.6.4")
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FL_LIBRARY (ADVANCED)
linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
[Failed to reload]

CMake WxWidgets project successfully built on linux but not on windows

I've managed to build a WxWidgets based on CMake on Ubuntu 19.10, but failed on Windows 10, saying that it cannot find WxWidgets, though I've built it successfully (static, release and with unicode support).
WxWidgets path is C:\wxWidgets-3.1.3 and the build directory is C:\wxWidgets-3.1.3\msw-release.
The makefile is
cmake_minimum_required(VERSION 3.0)
project(ChessPgnReviser VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
ADD_DEFINITIONS(-Wall -Wno-sign-compare -O2)
set(SRCS
src/main.cpp
)
set (HEADERS
)
message( "--Root--" ${wxWidgets_ROOT_DIR} )
message( "--Lib dir--" ${wxWidgets_LIB_DIR} )
add_executable(ChessPgnReviser ${SRCS} ${HEADERS})
find_package(wxWidgets COMPONENTS net gl core base)
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
target_link_libraries(ChessPgnReviser ${wxWidgets_LIBRARIES})
else()
message(FATAL_ERROR "Failed to find WxWidgets library")
endif()
I'm using Msys 64 bit in order to compile the project. At the bottom of its subfolder etc/profile, I've added
PATH=$PATH:/c/dev/cmake/bin
wxWidgets_ROOT_DIR=/c/wxWidgets-3.1.3
wxWidgets_LIBRARIES=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_LIB_DIR=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_INCLUDE_DIRS=$wxWidgets_ROOT_DIR/include
So I've tried
$ mkdir build && cd build
$ cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - 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: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--
--Lib dir--
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
Also, thanks to #squareskittles, I also tried:
$ cmake .. -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR="C:\wxWidgets-3.1.3" -DwxWidgets_LIB_DIR="C:\wxWidgets-3.1.3\msw-release\lib"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - 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: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--C:\wxWidgets-3.1.3
--Lib dir--C:\wxWidgets-3.1.3\msw-release\lib
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
You can find the content of the msw-release folder : there.
Also:
$ ls /c/wxWidgets-3.1.3/msw-release/lib/
libwx_baseu_net-3.1.a libwx_baseu-3.1.a libwx_mswu_aui-3.1.a libwx_mswu_gl-3.1.a libwx_mswu_media-3.1.a libwx_mswu_qa-3.1.a libwx_mswu_richtext-3.1.a libwx_mswu_webview-3.1.a libwxregexu-3.1.a wx
libwx_baseu_xml-3.1.a libwx_mswu_adv-3.1.a libwx_mswu_core-3.1.a libwx_mswu_html-3.1.a libwx_mswu_propgrid-3.1.a libwx_mswu_ribbon-3.1.a libwx_mswu_stc-3.1.a libwx_mswu_xrc-3.1.a libwxscintilla-3.1.a
So did I forget something ?
To properly detect wxWidgets you need wx-config.
A Windows version of wx-config exists and can be downloaded from: https://github.com/kowey/wx-config-win
To make wx-config know where your wxWidgets is, you need set the following environment variables:
WXWIN (in your case to C:/wxWidgets-3.1.3)
WXCFG (in your case to something like msw/gcc_mswu).

Using KF5 with CMake

I'm trying to use the KPlotting widget with a Qt (v5.14) project that uses CMake (v3.10.2).
I installed the KDE Extra CMake Modules by cloning the repo, then running: cmake, make, sudo make install.
I added find_package(KF5Plotting) to my top-level CMakeLists.txt file, and target_link_libraries(${PROJECT_NAME} KF5::Plotting) in the CMakeLists.txt file in my src directory. However, when I compile I get the following error:
ui_mainwindow.h:30:10: fatal error: kplotwidget.h: No such file or directory
#include <kplotwidget.h>
This seems to indicate that the call to find_package didn't work, but I'm unsure how to check. Am I simply missing an include directory directive in CMake? Any help on how to get this to compile would be greatly appreciated!
UPDATE:
If I add REQUIRED to find_package, nothing seems to change, and the output is simply:
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'portaudio-2.0'
-- Found portaudio-2.0, version 19
-- Found hamlib library at: /usr/local/lib/libhamlib.so
-- Found hamlib static library at: /usr/local/lib/libhamlib.a
-- Found hamlib static modules:
-- Found hamlib include directory at: /usr/local/include
-- Found sox library: /usr/lib/x86_64-linux-gnu/libsox.so
-- Found sox headers: /usr/include
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- system
-- filesystem
-- Found FFTW: /usr/include found components: FLOAT_LIB
boost lib: /usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so
boost inc:/usr/include
fftw lib: /usr/lib/x86_64-linux-gnu/libfftw3.so;/usr/lib/x86_64-linux-gnu/libfftw3f.so;/usr/lib/x86_64-linux-gnu/libfftw3l.so;/usr/lib/x86_64-linux-gnu/libfftw3_threads.so;/usr/lib/x86_64-linux-gnu/libfftw3f_threads.so;/usr/lib/x86_64-linux-gnu/libfftw3l_threads.so;/usr/lib/x86_64-linux-gnu/libfftw3_omp.so;/usr/lib/x86_64-linux-gnu/libfftw3f_omp.so;/usr/lib/x86_64-linux-gnu/libfftw3l_omp.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wspeirs/src/sdhr/build
The top-level CMakeLists.txt file can be found here: https://gist.github.com/wspeirs/1948869bf7fdb6f943c143b2a223fa54
Also, I installed KPlotting via apt (libkf5plotting-dev & libkf5plotting5) on Ubuntu 18.04

Running cmake in a different build directory on Windows

I run CMake using cmake .. in order to make it output all the generated files in a different directory. This runs fine on Ubuntu, but breaks on Windows 10 when I try to run it. Running cmake . from the root project directory seems to work fine on both platforms. The output of cmake .. on Windows is:
PS D:\Development\cpp\hello-vulkan\build> cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
The CMakeLists.txt is specified here:
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
cmake_minimum_required(VERSION 3.10)
project(hello_vulkan)
# Download and setup GLFW
set(GLFW_DIR ${PROJECT_SOURCE_DIR}/lib/glfw)
set(GLFW_BINARY_DIR ${GLFW_DIR}/bin)
ExternalProject_Add(
glfw
PREFIX ${GLFW_DIR}
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.2.1
INSTALL_DIR ${GLFW_BINARY_DIR}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GLFW_BINARY_DIR}
)
# Link Vulkan and GLFW
set(VULKAN_DIR ${PROJECT_SOURCE_DIR}/lib/vulkan)
include_directories(${VULKAN_DIR}/include)
link_directories(
${VULKAN_DIR}/lib
${GLFW_BINARY_DIR}
)
# Setup project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build/)
set(SOURCES source/main.cpp)
add_executable(hello_vulkan ${SOURCES})
add_dependencies(hello_vulkan glfw)
Any ideas what to do for it to work when running from a different directory on Windows?
Edit:
Here is the output from cmake .. on Ubuntu:
cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/d/Development/cpp/hello-vulkan/build