Introducing library paths in CMake - c++

I want to build a project which requires opencv.
I have set up opencv and added these variables to environment variables:
OPENCV_DIR -> c:\opencv\build\x86\vc12
PATH -> %OPENCV_DIR%\bin
Then I do the following:
mkdir build
cd build
set OpenCV_DIR="C:\opencv\build"
cmake -G "Visual Studio 14 2015" -D OpenCV_DIR=%OpenCV_DIR% ..
But I get these errors:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.6/Modules/FindBoost.cmake:1753 (message):
Unable to find the requested Boost libraries.
Boost version: 1.61.0
Boost include path: C:/Program Files/boost_1_61_0
Could not find the following Boost libraries:
boost_system
boost_filesystem
boost_signals
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
CMakeLists.txt:88 (find_package)
CMake Error at CMakeLists.txt:89 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "C:/Users/vahab/Desktop/PartsBasedDetector-master/PartsBasedDetector-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/vahab/Desktop/PartsBasedDetector-master/PartsBasedDetector-master/build/CMakeFiles/CMakeError.log".
For now I don't care about the error with boost library. I just want to know why it doesn't find opencv while I have set up the related variables. I have explored other stackoverflow pages but found no working answer. Can anyone help?
Thanks

Related

Cmake not able to find CGAL library(installed using vcpkg)

This is the error message:
CMake Error at D:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake:788 (_find_package):
By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CGAL", but
CMake did not find one.
Could not find a package configuration file provided by "CGAL" with any of
the following names:
CGALConfig.cmake
cgal-config.cmake
Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set
"CGAL_DIR" to a directory containing one of the above files. If "CGAL"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:16 (find_package)
I am trying to use the vcpkg toolchain file when building the project in Cmake; so all my installed libraries are available for Cmake but it is not working.

CMake can't find protobuf when compiling Google's protobuf example

I am trying to solve this problem for 2 days now with no luck. I've read an endless number of threads allover the web and tried a lot of suggestions but so far with no luck.
I'm doing this on Windows 10 with VS2017 and most recent VS Code installed. I installed protobuf with vcpkg install protobuf:
The package protobuf:x64-windows provides CMake targets:
find_package(protobuf CONFIG REQUIRED)
target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
I downloaded Google's example code and extracted it on my drive. The .PROTO file compiles without a problem:
d:\protobuf-3.12.2\examples>protoc -I=d:\protobuf-3.12.2\examples --cpp_out=d:\protobuf-3.12.2\examples d:\protobuf-3.12.2\examples\addressbook.proto
and creates the two files "addressbook.pb.cc" and "addressbook.pb.h" as expected.
Now when I try to compile the project in Visual Studio Code it constantly fails no matter how I modify the CMakeLists.txt file. As mentioned I went through dozens of threads regarding this problem and tried a lot with no luck.
Update 29.05.2020
I checked that protobuf is installed just once and indeed the demo package also included a full protobuf installation. I removed this extra demo package and un-/installed protobuf with vcpgk. I then compiled the .proto file with protoc (which is in my path) and got the two files "addressbook.pb.cc" and "addressbook.pb.h".
Then I tried to compile the project again, this time using the CMakeLists.txt that came with the demo.
The relevant part seems to be right in the beginning:
# Minimum CMake required
cmake_minimum_required(VERSION 2.8.12)
# Project
project(protobuf-examples)
# Find required protobuf package
find_package(protobuf CONFIG REQUIRED)
if(protobuf_VERBOSE)
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
endif()
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
Compiling this gives me:
[main] Building folder: examples
[main] Configuring folder: examples
[cms-client] Configuring using the "Visual Studio 15 2017" CMake generator with platform "x64" and toolset "host=x64"
[cmake] Selecting Windows SDK version 10.0.17763.0 to target Windows
...
[cmake] CMake Error at CMakeLists.txt:8 (find_package):
[cmake] Could not find a package configuration file provided by "protobuf" with any
[cmake] of the following names:
[cmake]
[cmake] protobufConfig.cmake
[cmake] protobuf-config.cmake
[cmake]
[cmake] Add the installation prefix of "protobuf" to CMAKE_PREFIX_PATH or set
[cmake] "protobuf_DIR" to a directory containing one of the above files. If
[cmake] "protobuf" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake]
[cmake]
[cmake] Configuring incomplete, errors occurred!
[cmake] See also "d:/vcpkg/buildtrees/protobuf/src/v3.12.0-8ba83cbbdb/examples/build/CMakeFiles/CMakeOutput.log".
[cms-driver] Error during CMake configure: [cmake-server] Configuration failed.
The file protobuf-config.cmake can be found multiple times in the protobuf folder:
D:\vcpkg\buildtrees\protobuf\<BUILDCFG>\share\protobuf\protobuf-config.cmake
D:\vcpkg\installed\<BUILDCFG>\share\protobuf\protobuf-config.cmake
D:\vcpkg\packages\<BUILDCFG>\share\protobuf\protobuf-config.cmake
What could be the cause that CMake can't locate these files?
Fair warning I am no expert.
I ran in to a similar problem in my own build trying to get Boost working and I think it has to do with your environment variables and how you have your Visual Studio setup. While you are setting crucial things such as
SET(PROTOBUF_INCLUDE_DIR "d:/vcpkg/packages/protobuf_x64-windows/include/")
The actual find_package(protobuf CONFIG REQUIRED) throws these settings out the window. Once it finds that config file it only cares about what the config file is finding, I think this is the cause of how your first MESSAGE has the right one, and then your 2nd one doesn't find one.
Are you positive you only have one installation of protobuf on your machine?
It appears to be finding this "used as include directory in directory D:/protobuf-3.12.2/examples"
yet you are trying to find "D:/vcpkg/packages/protobuf_x64-windows" no?
Try adding a "-DCMAKE_PREFIX_PATH="d:/vcpkg/packages/protobuf_x64-windows" to your CMake options in Visual Studio
Good luck and sorry if this doesn't help, I'm relatively new to programming but its worth a try.
in this thread fraser solved the problem but if you need to develop according to protobuf CMake config and find_package command in CMake for finding protobuf libraries. your protobuf library must be compiled with CMake and do not use configure routine .
after compile protobuf with CMake , a config file named protobuf-config.cmake will be generated into the prefix/lib/CMake/protobuf directory.
If the problem is in finding the protobuf installation then your protobuf path isn't on the Environment Variables try adding that to your path and let me know in case if it is there.
Will glad to help you more in case this doesn't work

Building basic C++ project with boost python v1.67 and cmake on Ubuntu

This is my first attempt to write a cmake file for a production level project, I'm just trying to locate the boost python(v 1.67.0) package using cmake.
I have a very small CMakeLists.txt.
cmake_minimum_required(VERSION 3.13)
find_package(Boost 1.67.0 REQUIRED COMPONENTS system python37)
if(Boost_FOUND)
message("Boost_FOUND")
endif()
It works fine if I just try to find system but fails when I add python37. As per the FindBoost documentation, I need to mention it the way I have mentioned it. This is the output that I get:
CMake Error at /usr/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
Unable to find the requested Boost libraries.
Boost version: 1.67.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_python37
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:2 (find_package)
-- Configuring incomplete, errors occurred!
When I run $ locate libboost_python I get the following output:
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1
/usr/lib/x86_64-linux-gnu/libboost_python27.so.1.67.0
/usr/lib/x86_64-linux-gnu/libboost_python3-py37.so.1.65.1
/usr/lib/x86_64-linux-gnu/libboost_python37.so.1.67.0
Given this output, I assume that the package/library is present.
So, I tried to add the following line in CMakeLists.txt:
set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
But the error remained. What am I missing here?
It looks like you are missing the dev package, as there is no /usr/lib/x86_64-linux-gnu/libboost_python27.so
Fix:
apt-get install libboost-python1.67-dev

How to configure cmake-based project for a build with Qt

here is a doc about that, but it doesn't look correct for me ,
so I've copied cmake instructions into my cmakelists.txt and it doesn't work.
it's clear why it doesn't work - because there is no one instruction how to search qt:
I suppose two cases:
some additional cmake instructions requires to set
some environment variables should be set
but nothing about that.
the instruction :
find_package(Qt5Widgets)
refers to extra cmake script from qt kit , isn't it?
I see the directory with that name (annd contains *.cmake scripts but another names) but there is no the script with this name
these are the only .cmake files with qt in names in cmake 3.6 :
cmake-3.6\Modules\DeployQt4.cmake
cmake-3.6\Modules\FindosgQt.cmake
cmake-3.6\Modules\FindQt.cmake
cmake-3.6\Modules\FindQt3.cmake
cmake-3.6\Modules\FindQt4.cmake
cmake-3.6\Modules\Qt4ConfigDependentSettings.cmake
cmake-3.6\Modules\Qt4Macros.cmake
cmake-3.6\Modules\UseQt4.cmake
===================
C:\dev\tools\CLion.RC\bin\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug
-G "CodeBlocks - MinGW Makefiles" C:\dev\workspace\algolist.v2 CMake Warning at CMakeLists.txt:14 (find_package): By not providing
"FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project has asked
CMake to find a package configuration file provided by "Qt5Widgets",
but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets"
with any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or
set "Qt5Widgets_DIR" to a directory containing one of the above
files. If "Qt5Widgets" provides a separate development package or
SDK, be sure it has been installed.
CMake Error at CMakeLists.txt:20 (target_link_libraries): Cannot
specify link libraries for target "helloworld" which is not built by
this project.
-- Configuring incomplete, errors occurred! See also "C:/dev/workspace/algolist.v2/cmake-build-debug/CMakeFiles/CMakeOutput.log".
seems it found Qt5Widgets, but absolutely not clear how it does this...
so it looks for cmake files inside Qt5Widgets folder, in Qt kit.
I can add this folder to the path but I don't think this is a valid way,
because there is a lot of subfolders with cmake files
Qt5.8 beta, built with MinGW, Win10, cmake 3.6
You need to use CMAKE_PREFIX_PATH.
For example:
cmake.exe -DCMAKE_PREFIX_PATH="C:/path/to/Qt/5.X/compiler/lib/cmake"

Cmake can't find Boost Folder

I am using windows 7 - 64bit and am trying to build a project. When I use cmake i get the error
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoos
t.cmake:1191 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
src/CMakeLists.txt:310 (find_package)
CMake Error at src/CMakeLists.txt:312 (message):
Boost C++ libraries not found. Please install or try setting BOOST_ROOT
I have set the variable to BOOST_ROOT to D:\MyProject\boost_1_43_0\boost\
but i still get this . How can i resolve this issue.
Placing boost in a subfolder of the project is not standard CMake practice for locating boost. I have boost x64 - MSVC 2010 installed in Program Files and CMake automatically locates it.
Boost_DIR : C:/Program Files/Boost/share/cmake/boost
Boost_INCLUDE_DIR : C:/Program Files/Boost/include
You can attempt to set Boost_DIR at the system environment variables level as well.