How can i fix tbb on CMake - c++

I have this problem.
CMake Error at CMakeLists.txt:14 (find_package): By not providing
"FindTBB.cmake" in CMAKE_MODULE_PATH this project has asked CMake to
find a package configuration file provided by "TBB", but CMake did
not find one.
I could not find a package configuration file provided by "TBB" with any of the following names:
TBBConfig.cmake
tbb-config.cmake
Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set
"TBB_DIR" to a directory containing one of the above files. If
"TBB" provides a separate development package or SDK, be sure it has
been installed.
how can i fix this?
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(deneme)
set(CMAKE_CXX_STANDARD 11)
include("C:/yunus/Git/inteltbb/tbb/cmake/TBBBuild.cmake")
tbb_build(TBB_ROOT "C:/yunus/Git/inteltbb/tbb" CONFIG_DIR TBB_DIR)
find_package(TBB REQUIRED tbb)
add_executable(deneme main.cpp ToDo.cpp ToDo.h)

TBB does not come by default with a FindTBB.cmake module so the guidelines in the error message are a bit misleading.
If your project provides the corresponding FindTBB.cmake module you need to add the path to it and the path to the TBB installation to your CMake call, i.e.
cmake . -G "<your generator here>" -DTBB_DIR=<path to TBB installation> -DCMAKE_PREFIX_PATH=<path to FindTBB.cmake>
Otherwise you need to download a suitable FindTBB.cmake module e.g. https://github.com/schuhschuh/cmake-basis-modules/blob/develop/FindTBB.cmake
This one uses TBB_ROOT instead of TBB_DIR.
Edit:
Try the binary package integration of TBB first.
Comment the include(...) and the tbb_build(...) command and add
target_link_libraries(deneme ${TBB_IMPORTED_TARGETS})
to your CMakeLists.txt after the add_executable call. Then call
cmake . -G "<your generator here>" -DCMAKE_PREFIX_PATH=<path to your TBB installation>

Related

How resolve the error find_package not providing in CMake [duplicate]

I wrote a CMakeLists.txt for a project in C++, which uses OpenCV libraries. When I try to create the project using cmake, I get the next configuration problem:
CMake Error at CMakeLists.txt:15 (find_package):
Could not find module FindOpenCV.cmake or a configuration file for package
OpenCV.
Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
directory containing a CMake configuration file for OpenCV. The file will
have one of the following names:
OpenCVConfig.cmake
opencv-config.cmake
The fact is that I have an environment variable for the path which I use in Visual Studio with no problems. If I don't include OpenCV, then I can configure and generate with no problem, but I need to solve the problem. I don't understand why cmake cannot find the OpenCV path or how to fix it.
I also used the recommendations mentioned in this link:
FindOpenCV.cmake
Does anybody had this problem too?
The error you're seeing is that CMake cannot find a FindOpenCV.cmake file, because cmake doesn't include one out of the box. Therefore you need to find one and put it where cmake can find it:
You can find a good start here. If you're feeling adventurous you can also write your own.
Then add it somewhere in your project and adjust CMAKE_MODULE_PATH so that cmake can find it.
e.g., if you have
CMakeLists.txt
cmake-modules/FindOpenCV.cmake
Then you should do a
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
In your CMakeLists.txt file before you do a find_package(OpenCV)
If you are on Linux, you just need to fill the OpenCV_DIR variable with the path of opencv (containing the OpenCVConfig.cmake file)
export OpenCV_DIR=<path_of_opencv>
apt-get install libopencv-dev
export OpenCV_DIR=/usr/share/OpenCV
the header of cpp file should contain:
#include
#include "opencv2/highgui/highgui.hpp"
#include
#include
not original cv.h
find / -name "OpenCVConfig.cmake"
export OpenCV_DIR=/path/found/above
I had this exact same problem. I fixed it by adding the following line to my FindOpenCV.cmake file. Put it anywhere at the top before the rest of the code.
set (OpenCV_DIR /home/cmake/opencv/compiled) #change the path to match your complied directory of opencv
Basically you are telling FindOpenCV.cmake where to find opencv files assuming the other compilation can find the FindOpenCV.cmake
I faced the same error. In my case this "OpenCVConfig.cmake" file is located in /usr/local/share/OpenCV. In CMakeLists.txt add the line
set(OpenCV_DIR /usr/local/share/OpenCV)
as suggested by the error message.
if you are on windows, you can add opencv path to OpenCV_DIR yourself.
(OpenCV_DIR is in the red region)
the path is like "D:/opencv244/build".
you can find file "OpenCVConfig.cmake" under the path.
Another possibility is to denote where you can find OpenCV_DIR in the CMakeLists.txt file. For example, the following cmake scripts work for me:
cmake_minimum_required(VERSION 2.8)
project(performance_test)
set(OpenCV_STATIC ON)
set(OpenCV_CUDA OFF)
set(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../install")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})
file(GLOB my_source_files ./src/*)
add_executable( performance_test ${my_source_files})
target_link_libraries(performance_test ${OpenCV_LIBS})
Just to remind that you should set OpenCV_STATIC and OpenCV_CUDA as well before you invoke OpenCVConfig.cmake. In my case the built library is static library that does not use CUDA.
On my Fedora machine, when I typed "make" I got an error saying it could not find "cv.h". I fixed this by modifying my "OpenCVConfig.cmake" file.
Before:
SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib64")
After:
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
SET(OpenCV_LIB_DIR "/usr/lib64")
I am using Windows and get the same error message. I find another problem which is relevant.
I defined OpenCV_DIR in my path at the end of the line. However when I typed "path" in the command line, my OpenCV_DIR was not shown. I found because Windows probably has a limit on how long the path can be, it cut my OpenCV_DIR to be only part of what I defined. So I removed some other part of the path, now it works.
I had the same error, I use windows. I add "C:\opencv\build" (opencv folder) to path at the control pannel.
So, That's Ok!!
For me (on Ubuntu), I just run:
sudo apt-get install libopencv-dev
Followed #hugh-pearse 's and #leszek-hanusz 's answers, with a little tweak. I had installed opencv from ubuntu 12.10 repository (libopencv-)* and had the same problem. Couldn't solve it with export OpenCV_DIR=/usr/share/OpenCV/ (since my OpenCVConfig.cmake whas there). It was solved when I also changed some lines on the OpenCVConfig.cmake file:
# ======================================================
# Include directories to add to the user project:
# ======================================================
# Provide the include directories to the caller
#SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
# ======================================================
# Link directories to add to the user project:
# ======================================================
# Provide the libs directory anyway, it may be needed in some cases.
#SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib")
SET(OpenCV_LIB_DIR "/usr/lib")
LINK_DIRECTORIES(${OpenCV_LIB_DIR})
And that worked on my Ubuntu 12.10. Remember to add the target_link_libraries(yourprojectname ${OpenCV_LIBS}) in your CMakeLists.txt.
When you install the libraries in the c drive (windows). the CMakeLists.txt shoud be looking like below:
cmake_minimum_required(VERSION 3.0.0)
project(test_opencv VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test_opencv main.cpp)
target_link_libraries(test_opencv ${OPENCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
finding the package and include directories
when building the project in VS code. Run the visual studio code with admin rights as the OpenCV is installed inside C drive.

Link SDL2_net with CMake

I'm trying to link SDL2_net (SDL_net 2.0) to my project via CMake, but after searching around I've yet to find a solution. My CMakeLists.txt currently looks like this:
1 cmake_minimum_required (VERSION 3.7)
2 project (SDL_net_test)
3 include (FindPkgConfig)
4 include (FindSDL_net)
5
6 pkg_search_module (SDL2 REQUIRED sdl2)
7 pkg_search_module (SDL_NET REQUIRED sdl2_net)
8
9 include_directories (${SDL2_INCLUDE_DIRS} ${SDL_NET_INCLUDE_DIRS})
10
11 add_executable (SDL_net_test main.cpp)
12 target_link_libraries (SDL_net_test ${SDL2_LIBRARIES} ${SDL_NET_LIBRARIES})
However, when I attempt to run CMake it gives me the following error(s):
-- Could NOT find SDL_net (missing: SDL_NET_LIBRARIES SDL_NET_INCLUDE_DIRS)
-- Checking for one of the modules 'sdl2_net'
CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:659 (message):
None of the required 'sdl2_net' found
Call Stack (most recent call first):
CMakeLists.txt:7 (pkg_search_module)
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:
SDL_NET_INCLUDE_DIR (ADVANCED)
used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
SDL_NET_LIBRARY (ADVANCED)
linked by target "SDL_net_test" in directory /home/neboula/Programming/sandbox/sdl2_net
-- Configuring incomplete, errors occurred!
See also "/home/neboula/Programming/sandbox/sdl2_net/build/CMakeFiles/CMakeOutput.log".
I have installed the SDL2_net-devel package from my package manager (dnf on Fedora 29), and I've successfully linked SDL2 and SDL2_image previously basing it on this answer, which worked brilliantly. I also found this, but I'm not entirely sure how to use it. How should I go about this?
Since the person who provided an answer only posted a comment about it, I'll put it down here myself.
The solution was seemingly very simple: I had written pkg_search_module (SDL_NET REQUIRED sdl2_net), while it was supposed to be pkg_search_module (SDL_NET REQUIRED SDL2_net).
To easily integrate the SDL2 library and other related libraries (SDL2_net, SDL2_mixer, ...), I developed modern cross-platform CMake modules that can be used as follows:
Clone SDL2 CMake modules inside our project:
git clone https://github.com/aminosbh/sdl2-cmake-modules cmake/sdl2
Add the following lines in your main CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
find_package(SDL2 REQUIRED)
find_package(SDL2_net REQUIRED)
target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2:Net)
You can even specify a custom path to find the SDL2, SDL2_net, ... useful specially on Windows.
cmake .. -DSDL2_PATH="/path/to/sdl2" -DSDL2_NET_PATH="/path/to/sdl2-net"
For sure, you should not forgot to install the specific packages:
# Fedora/RPM
sudo yum install SDL2-devel SDL2_net-devel
# Debian/Ubuntu
sudo apt install libsdl2-dev libsdl2-net-dev

CMake not providing "Findlibusb-1.0.cmake" error

I am receiving the following CMake Error:
Errors << project_ros:cmake
/home/nando/project_ws/logs/project_ros/build.cmake.020.log CMake
Error at /home/nando/project_ws/src/project_ros/CMakeLists.txt:22
(find_package): By not providing "Findlibusb-1.0.cmake" in
CMAKE_MODULE_PATH this project has asked CMake to find a package
configuration file provided by "libusb-1.0", but CMake did not find
one.
Could not find a package configuration file provided by "libusb-1.0"
with any of the following names:
libusb-1.0Config.cmake
libusb-1.0-config.cmake
Add the installation prefix of "libusb-1.0" to CMAKE_PREFIX_PATH or
set "libusb-1.0_DIR" to a directory containing one of the above
files. If "libusb-1.0" provides a separate development package or
SDK, be sure it has been installed.
However, I think I am providing "Findlibusb-1.0.cmake" in CMAKE_MODULE_PATH correctly.
This is in my CMakeLists.txt:
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_SOURCE_DIR}/project_ros/cmakeModules/")
And in src/project_ros/cmakeModules I have Findlibusb-1.0.cmake.
In this thread the same error was appearing but the reason was a typo I don't have.
Any other idea?

CMake can not determine linker language for target: azurestorage error

I'm very new to C++ programming and having some trouble using CMake to add the azure-storage-cpp repository to my VS solution.
Here is the build error I am getting in VS, when I attempt to build the azure storage project.
CMake can not determine linker language for target: azurestorage
Here is my CMake entry:
ExternalProject_Add( azurestorage
PREFIX azurestorage
GIT_REPOSITORY https://github.com/Azure/azure-storage-cpp.git
GIT_TAG master
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../azurestorage
SOURCE_SUBDIR Microsoft.WindowsAzure.Storage)
I tried adding SET_TARGET_PROPERTIES(azurestorage PROPERTIES LINKER_LANGUAGE CXX) to my CMakeList.txt file but it doesn't help. I've also read on other forums that the repo needs to have a .cpp and .h file in the root directory for CMake to know which language. However since the azure-storage-cpp repo isn't mine, I don't have the ability to add such files.
I'm using VS2015 on Windows10
What am I doing wrong? Any and all help is appreciated.
I've given your example a try and the relevant error message is more to the top of CMake's output:
-- Unsupported Build Platform.
So if you want to add it, don't use ExternalProject_Add(). The library's included CMakeLists.txt is for Unix/Linux/OSX.
But it comes with an existing .vcproj for VS2015 which you can include into your project with include_external_msproject():
find_package(Git REQUIRED)
execute_process(
COMMAND "${GIT_EXECUTABLE}" clone https://github.com/Azure/azure-storage-cpp.git
)
set(NUGET_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/azure-storage-cpp/tools/NuGet.exe")
execute_process(
COMMAND "${NUGET_EXECUTABLE}" restore "azure-storage-cpp/Microsoft.WindowsAzure.Storage.v140.sln"
)
include_external_msproject(
azurestorage
"azure-storage-cpp/Microsoft.WindowsAzure.Storage/Microsoft.WindowsAzure.Storage.v140.vcxproj"
)

CMake is not able to find BOOST libraries

I tried everything like:
Configure environment variable
Make fresh build
Re-install BOOST from source
sudo apt-get install libboost-all-dev
But still getting following Errors:
CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (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):
CMakeLists.txt:147 (find_package)
CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (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.
Source code directory for boost: /usr/local/src/boost_1_45_0
Boost Library path: /usr/local/lib
Boost Header file: /usr/local/include/boost
Here is bashrc file:
BOOST_ROOT="/usr/local/src/boost_1_45_0"
Boost_LIBRARY_DIRS="/usr/local/lib"
BOOST_INCLUDEDIR="/usr/local/src/boost_1_45_0"
How to solve these Errors? Am i missing something?
Edit:
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN -DBOOST_ROOT=/usr/local/src/boost_1_45_0 -DBOOST_INCLUDEDIR=/usr/local/include/boost -DBOOST_LIBRARYDIR=/usr/local/lib -DPYTHON_LIBRARIES=/usr/local/lib/python2.7 -DPYTHON_INCLUDE_DIRS=/usr/include/python2.7 -DCMA-DRDK_BUILD_PYTHON_WRAPPERS=
Try to complete cmake process with following libs:
sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev
I'm using this to set up boost from cmake in my CMakeLists.txt. Try something similar (make sure to update paths to your installation of boost).
SET (BOOST_ROOT "/opt/boost/boost_1_57_0")
SET (BOOST_INCLUDEDIR "/opt/boost/boost-1.57.0/include")
SET (BOOST_LIBRARYDIR "/opt/boost/boost-1.57.0/lib")
SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Fatal error: Boost (version >= 1.55) required.")
else()
message(STATUS "Setting up BOOST")
message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
message(STATUS " Library - ${Boost_LIBRARY_DIRS}")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)
This will either search default paths (/usr, /usr/local) or the path provided through the cmake variables (BOOST_ROOT, BOOST_INCLUDEDIR, BOOST_LIBRARYDIR). It works for me on cmake > 2.6.
I got the same error the first time I wanted to install LightGBM on python (GPU version).
You can simply fix it with this command line :
sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev
the boost libraries will be installed and you'll be fine to continue your installation process.
seems the answer is in the comments and as an edit but to clarify this should work for you:
export BUILDDIR='your path to build directory here'
export SRCDIR='your path to source dir here'
export BOOST_ROOT="/opt/boost/boost_1_57_0"
export BOOST_INCLUDE="/opt/boost/boost-1.57.0/include"
export BOOST_LIBDIR="/opt/boost/boost-1.57.0/lib"
export BOOST_OPTS="-DBOOST_ROOT=${BOOST_ROOT} -DBOOST_INCLUDEDIR=${BOOST_INCLUDE} -DBOOST_LIBRARYDIR=${BOOST_LIBDIR}"
(cd ${BUILDDIR} && cmake ${BOOST_OPTS} ${SRCDIR})
you need to specify the arguments as command line arguments or you can use a toolchain file for that, but cmake will not touch your environment variables.
I just want to point out that the FindBoost macro might be looking for an earlier version, for instance, 1.58.0 when you might have 1.60.0 installed. I suggest popping open the FindBoost macro from whatever it is you are attempting to build, and checking if that's the case. You can simply edit it to include your particular version. (This was my problem.)
Thanks Paul-g for your advise. For my part it was a bit different.
I installed Boost by following the Step 5 of : https://www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html
And then I add PATH directory in the "FindBoos.cmake", located in /usr/local/share/cmake-3.5/Modules :
SET (BOOST_ROOT "../boost_1_60_0")
SET (BOOST_INCLUDEDIR "../boost_1_60_0/boost")
SET (BOOST_LIBRARYDIR "../boost_1_60_0/libs")
SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
Long answer to short, if you install boost in custom path, all header files must in ${path}/boost/.
if you want to konw why cmake can't find the requested Boost libraries after you have set BOOST_ROOT/BOOST_INCLUDEDIR, you can check cmake install location path_to_cmake/share/cmake-xxx/Modules/FindBoost.
cmake which will find Boost_INCLUDE_DIR in boost/config.hpp in BOOST_ROOT. That means your boost header file must in ${path}/boost/, any other format (such as ${path}/boost-x.y.z) will not be suitable for find_package in CMakeLists.txt.
I had the same issue inside an alpine docker container, my solution was to add the boost-dev apk library because libboost-dev was not available.