So My Workspace Screenshot After Trying a while i cant Get Cmake To find the required packages even after i did everything as shown in vcpkg
cmake_minimum_required(VERSION 3.0.0)
project(TEst VERSION 0.1.0)
include(CTest)
enable_testing()
set(CMAKE_TOOLCHAIN_FILE "N:/Vc-PKG/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(TEst PRIVATE glfw)
add_executable(TEst main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
and my Vcpkg install directory is N:\Vc-PKG\vcpkg
i also added these lines in vscode
"C_Cpp.default.includePath": [
"N:/Vc-PKG/vcpkg/installed/x64-windows/include",
"N:/Vc-PKG/vcpkg/installed/x86-windows/include",
],
"c-cpp-flylint.cppcheck.includePaths": [
"N:\\Vc-PKG\\vcpkg\\installed\\x64-windows\\include",
"N:\\Vc-PKG\\vcpkg\\installed\\x86-windows\\include",
],
"cmake.generator": "MinGW Makefiles",
The output i get For the following is
[main] Configuring folder: Junks
[proc] Executing command: N:\MSYS64\mingw64\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=N:\MSYS64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=N:\MSYS64\mingw64\bin\x86_64-w64-mingw32-g++.exe "-Hl:/Programming Projects/Vs Code/Junks" "-Bl:/Programming Projects/Vs Code/Junks/build" -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake] Could not find a package configuration file provided by "glfw3" with any of
[cmake] the following names:
[cmake]
[cmake] glfw3Config.cmake
[cmake] glfw3-config.cmake
[cmake]
[cmake] Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
[cmake] "glfw3_DIR" to a directory containing one of the above files. If "glfw3"
[cmake] provides a separate development package or SDK, be sure it has been
[cmake] installed.
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "L:/Programming Projects/Vs Code/Junks/build/CMakeFiles/CMakeOutput.log".
[cmake]
Please any help would be much apricated, sry if i made a mistake this is the 1st time i am posting a question.
You can't set CMAKE_TOOLCHAIN_FILE after the call to project(). That's the command responsible for loading the toolchain file in the first place. Move it before the call to project() or better yet: set it at the command line or in a preset.
Also, unless you're actually using CMake 3.0.0, you shouldn't set it as a minimum. CMake is not forwards compatible, so without actually testing it on the minimum version, you have no way of knowing whether it will work that far back.
Related
I wanted to make a GD mod using c++, but when it compiles, i get this error:
[cmake] CMake Error at CMakeLists.txt:5 (project):
[cmake] Generator
[cmake]
[cmake] Unix Makefiles
[cmake]
[cmake] does not support platform specification, but platform
[cmake]
[cmake] darwin
[cmake]
[cmake] was specified.
[cmake]
[cmake]
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring incomplete, errors occurred!
my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.3.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(IlliaGDMod VERSION 1.0.0)
# Use GLOB_RECURSE instead of GLOB
# to recursively add all source files
# under src/
file(GLOB SOURCES
src/*.cpp
)
# Set up the mod binary
add_library(${PROJECT_NAME} SHARED ${SOURCES})
if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Geode SDK not found")
else()
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
endif()
set(GEODE_LINK_NIGHTLY ON)
add_subdirectory($ENV{GEODE_SDK} $ENV{GEODE_SDK}/build)
target_link_libraries(${PROJECT_NAME} geode-sdk)
create_geode_file(${PROJECT_NAME})
I used VSCode 1.72.2, compiler clang
Does anyone have any ideas on why this happens?
also, i used the visual studio code cmake tools to compile it
I want to include Python.h and numpy/arrayobject.h in my C++ script. But it cannot open these source files.
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(myProj VERSION 0.1.0 DESCRIPTION "myProj")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(PythonLibs REQUIRED) <--- work
find_package(Python3 3.6 COMPONENTS Interpreter NumPy REQUIRED) <--- not work
include_directories(${PYTHON_INCLUDE_DIRS})
add_executable(myProj main.cc)
target_link_libraries(myProj ${PYTHON_LIBRARIES} Python3:NumPy)
Error
[cmake] CMake Error at CMakeLists.txt:9 (find_package):
[cmake] By not providing "FindPython3.cmake" in CMAKE_MODULE_PATH this project has
[cmake] asked CMake to find a package configuration file provided by "Python3", but
[cmake] CMake did not find one.
[cmake]
[cmake] Could not find a package configuration file provided by "Python3"
[cmake] (requested version 3.6) with any of the following names:
[cmake]
[cmake] Python3Config.cmake
[cmake] python3-config.cmake
[cmake]
[cmake] Add the installation prefix of "Python3" to CMAKE_PREFIX_PATH or set
[cmake] "Python3_DIR" to a directory containing one of the above files. If
[cmake] "Python3" provides a separate development package or SDK, be sure it has
[cmake] been installed.
Path of NumPy
(venv) cyan#linux01:~/TEMP$ python -c "import numpy; print(numpy.get_include())"
/home/cyan/venv/lib/python3.6/site-packages/numpy/core/include
Question
How can I revise my CMakeLists.txt so to include the header numpy/arrayobject.h in C++?
I'm not seeing a lot of documentation for FindPython3 or FindPython for CMake 3.0.0 so I'm not sure if that module included before CMake 3.12.0. Version 3.12 is the first occurence I could find in the cmake documentation.
The most likely thing is that you just need to change to using
cmake_minimum_required(VERSION 3.12.0)
Updating your CMake version is probably the simplest solution but again you might have good reason to limit the version and just telling you to update isn't much of a solution.
Another hackier solution would be to use one of the paths from Python_INCLUDE_DIRS or Python_LIBRARIES do some relative pathing from there. Something like
set(numpy_INCLUDE_DIR "${Python_INCLUDE_DIR}/../site-packages/numpy
/core/include")
include_directories(${Python_INCLUDE_DIRS} ${numpy_INCLUDE_DIR})
This however assumes that your python directories are setup as if they came from a python distribution and would in turn assume that everyone that uses this also has a distribution with the same file structure.
I am trying to use OpenCV in VS Code.
Here's what I've done:
Installed OpenCV for windows.
Added "C:\opencv\build\x64\vc15\bin","C:\opencv\build\x64\vc15\lib" PATH environment variable.
Here's my CMakeLists.txt file.
cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(opencvtest main.cpp)
target_link_libraries( opencvtest ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
But the file throws the following error:
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\TDM-GCC-64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\TDM-GCC-64\bin\x86_64-w64-mingw32-g++.exe -Hc:/Users/Administrator/Desktop/open -Bc:/Users/Administrator/Desktop/open/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- OpenCV ARCH: x64
[cmake] -- OpenCV RUNTIME: mingw
[cmake] -- OpenCV STATIC: OFF
[cmake] CMake Warning at C:/opencv/build/OpenCVConfig.cmake:190 (message):
[cmake] Found OpenCV Windows Pack but it has no binaries compatible with your
[cmake] configuration.
[cmake]
[cmake] You should manually point CMake variable OpenCV_DIR to your build of OpenCV
[cmake] library.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:7 (find_package)
[cmake]
[cmake]
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake] Found package configuration file:
[cmake]
[cmake] C:/opencv/build/OpenCVConfig.cmake
[cmake]
[cmake] but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
[cmake] NOT FOUND.
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
I am trying to run a C++ file in VS Code that includes <opencv2/opencv.hpp>.
As the error suggests, CMake found your OpenCV installation, but it is not compatible. What is it not compatible with? Your compiler. The OpenCV installation is built with MSVC 15 (it also includes a 14 build). You have asked CMake to use MinGW as your compiler. Libraries need to have been built with the same (well, with some leeway) compiler for everything to work.
You have two options:
Build OpenCV yourself with MinGW, or try a third-party MinGW binary distribution of OpenCV. Web searches for "opencv mingw" turn up some
possibilities.
Use the MSVC compiler for your project. Microsoft offers some free versions of its tools. Just be sure to install the optional older toolsets so that you have access to the VC 15 tools to match OpenCV.
I am using visual studio code on Ubuntu 20.04 and cmake tools for visual studio code.
I am trying to use opencv in a project. I used vcpkg to build OpenCV and it is installed:
The cmakeList.txt is as follow:
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_TOOLCHAIN_FILE /home/m/vcpkg/scripts/buildsystems/vcpkg.cmake)
project(testcmake VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
add_executable(testcmake main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
I also added this line to setting.json:
{
"cmake.configureOnOpen": false,
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "/home/m/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
but when I run cmake, I am getting this error:
[main] Building folder: cmakeTest
[main] Configuring folder: cmakeTest
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=/home/m/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-9 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-9 -H/home/m/MyData/sourceCode/cmakeTest -B/home/m/MyData/sourceCode/cmakeTest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/m/MyData/sourceCode/cmakeTest/build/CMakeFiles/CMakeOutput.log".
[cmake] CMake Error at CMakeLists.txt:7 (find_package):
[cmake] By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
[cmake] asked CMake to find a package configuration file provided by "OpenCV", but
[cmake] CMake did not find one.
[cmake]
[cmake] Could not find a package configuration file provided by "OpenCV" with any
[cmake] of the following names:
[cmake]
[cmake] OpenCVConfig.cmake
[cmake] opencv-config.cmake
[cmake]
[cmake] Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
[cmake] "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
[cmake] provides a separate development package or SDK, be sure it has been
[cmake] installed.
[cmake]
[cmake]
Why make can not find opencv using vcpkg?
Edit 1
I compiled OpenCV for x64:
opencv4:x64-linux 4.3.0#1 computer vision library
opencv4[dnn]:x64-linux Enable dnn module
opencv4[jpeg]:x64-linux JPEG support for opencv
opencv4[opengl]:x64-linux opengl support for opencv
opencv4[png]:x64-linux PNG support for opencv
opencv4[tiff]:x64-linux TIFF support for opencv
opencv4[webp]:x64-linux WebP support for opencv
opencv:x64-linux 4.3.0 Computer vision library
opencv[dnn]:x64-linux Enable dnn module
opencv[jpeg]:x64-linux JPEG support for opencv
opencv[opengl]:x64-linux opengl support for opencv
opencv[png]:x64-linux PNG support for opencv
opencv[tiff]:x64-linux TIFF support for opencv
opencv[webp]:x64-linux WebP support for opencv
I know that I should set the vcpkg triplets, how can I set it by default so all applications use it instead of putting it in cmake?
Update 2
I set the triplets as following but still getting the same error:
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_TOOLCHAIN_FILE /home/m/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(VCPKG_TARGET_TRIPLET x64-linux CACHE STRING "VCPKG Target Triplet to use")
project(testcmake VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
add_executable(testcmake main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
I want to use vcpkg in a CMake project in Windows, because I need boost and xerces that are both handled by this package manager.
I've the following CMakeLists.txt:
cmake_minimum_required (VERSION 3.12.0)
project (myproj)
set (CMAKE_PREFIX_PATH ${XERCES_ROOT})
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
# set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules)
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package (XercesC CONFIG REQUIRED)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
message (STATUS "binary dir is ${CMAKE_BINARY_DIR}")
include_directories (${CMAKE_BINARY_DIR}/${PROJECT_NAME}/)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories (${Boost_INCLUDE_DIRS})
include_directories (${XercesC_INCLUDE_DIRS})
set (PROJECT_SRC
code.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
add_dependencies (${PROJECT_NAME} UPDATE_RESOURCES)
target_link_libraries (${PROJECT_NAME} ${Boost_LIBRARIES} XercesC::XercesC)
Boost and xerces-c are installed with vcpkg. Since I'm using Visual Studio Code I'm setting vcpkg variables in settings.json:
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE" : "some/path/vcpkg/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
When I run che CMake I obtain following errors:
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:2132 (message):
[cmake] Unable to find the requested Boost libraries.
[cmake]
[cmake] Unable to find the Boost header files. Please set BOOST_ROOT to the root
[cmake] directory containing Boost or BOOST_INCLUDEDIR to the directory containing
[cmake] Boost's headers.
[cmake] Call Stack (most recent call first):
[cmake] D:/projects/vcpkg/scripts/buildsystems/vcpkg.cmake:233 (_find_package)
[cmake] src/myroject/CMakeLists.txt:24 (find_package)
[cmake]
[cmake]
[cmake] CMake Error at D:/Projects/vcpkg/installed/x64-windows/share/xercesc/vcpkg-cmake-wrapper.cmake:1 (_find_package):
[cmake] Could not find a package configuration file provided by "XercesC" with any
[cmake] of the following names:
[cmake]
[cmake] XercesCConfig.cmake
[cmake] xercesc-config.cmake
[cmake]
[cmake] Add the installation prefix of "XercesC" to CMAKE_PREFIX_PATH or set
[cmake] "XercesC_DIR" to a directory containing one of the above files. If
[cmake] "XercesC" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake] Call Stack (most recent call first):
[cmake] D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake:189 (include)
[cmake] src/ZLA/CMakeLists.txt:25 (find_package)
[cmake]
[cmake]
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "D:/Projects/zla/build/vscode/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
At the moment I've installed xerces with vcpkg commands, while boost is currently not installed, but I was expecting that during the execution of the cmake command, vcpkg will download and build needed build packages.
I've tried also the command line:
cmake -DCMAKE_TOOLCHAIN_FILE=D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ../
but the result is the same.
What I'm doing wrong? How can I use vcpkg successfully?
In theory it's as simple as (assuming vcpkg as installed in C:/vcpkg as it is for github actions);
Install your "foo" package with vcpkg install foo
Make sure your CMakeLists.txt finds and uses the package with;
find_package(FOO)
# Use these instead of the package doesn't have proper cmake
package support.
# find_path(FOO_INCLUDE_DIRS foo.h)
# find_library(FOO_LIBRARYS foo)
include_directories(${FOO_INCLUDE_DIRS})
target_link_libraries(myprogram ${FOO_LIBRARIES})
Run cmake with
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
But... this didn't work for me until I added --triplet x64-windows to the vcpkg install command.
The DCMAKE_TOOLCHAIN_FILE sets the various CMAKE_(SYSTEM_)?(PREFIX|LIBRARY|INCLUDE|FRAMEWORK)_PATH variables to enable the find_*() cmake functions to work, but note that these paths include the VCPKG_TARGET_TRIPLET. In my case the package install with vcpkg install <foo> defaulted to x86-windows but then invoking cmake with -DCMAKE_TOOLCHAIN_FILE=C:/.... defaulted to x64-windows so it couldn't find the the package.
Currently vcpkg defaults to the older x86 target, but modern Visual Studio (as used by githup actions) defaults to x64. The fix was to install the package with vcpkg -triplet x64-windows install <foo>. It took me way too long going down too many red-herring rabbit holes to discover this.
You need to install the packages beforehand (using vcpkg install ).
(Then you could specify the toolchain as a CMake option:
-DCMAKE_TOOLCHAIN_FILE=C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake
but this won't work if you already specify a toolchain, such as when cross-compiling.)
"include" it, instead, to avoid this problem:
Add this line to the project CMakeLists.txt before find_package():
include(/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake)
boost is currently not installed, but I was expecting that during the execution of the cmake command, vcpkg will download and build needed build packages.
This is not the case as far as I know. You need to install the packages you want with vcpkg beforehand for the triplet you plan to use (i.e. x64-windows). You will then need to ensure that the correct triplet is being used when you run CMake (check the VCPKG_TARGET_TRIPLET variable in your CMakeCache.txt). If it's incorrect, you can change it and re-configure using CMake.
Additionally, based on the error output you're getting, it doesn't seem that xerces has been installed properly either using vcpkg. You can check what is installed with vcpkg by running:
vcpkg list --triplet x64-windows
I had the same issue and just solved it either with:
set(CURL_DIR "C:/Libs/vcpkg/installed/x64-windows/share/curl")
or
list(APPEND CMAKE_PREFIX_PATH "C:/Libs/vcpkg/packages/curl_x64-windows/share/curl/")
I installed vcpkg under C:/Libs