Not able to link HDF5 path in CMake configuration - cmake

I'm trying to create make files of C++ code on a server doing
cmake ../
and I get the error
-- Could NOT find HDF5 (missing: HDF5_INCLUDE_DIRS) (found version "1.10.7")
CMake Error at src/CMakeLists.txt:180 (message):
HDF5 support was requested, but no HDF5 library was found on this system
I have installed HDF5 in /home/directory/ so I have HDF5 include and library files in
/home/directory/include
/home/directory/lib
I've tried to add in CMakeLists.txt the following lines:
set(HDF5_LIBRARIES "/home/directory/")
set(HDF5_CXX_LIBRARIES "/home/directory/")
set(HDF5_INCLUDE_DIRS "/home/directory/")
set(HDF5_CXX_INCLUDE_DIRS "/home/directory/")
But still getting the error.
I've also tried to export HDF5_ROOT=/home/directory/ without success.
The error come from the following lines in the code:
if (HDF5_FOUND)
target_include_directories(soft PUBLIC ${HDF5_INCLUDE_DIRS})
target_link_libraries(soft PUBLIC ${HDF5_LIBRARIES})
else (HDF5_FOUND)
message(FATAL_ERROR "HDF5 support was requested, but no HDF5 library was found on this system")
endif (HDF5_FOUND)
Any help?
Using CMake 3.19.3 and hdf5-1.10.7

Related

Use cmake FindBLAS to link OpenBLAS

I am using cmake 3.16, and I know that cmake supports finding OpenBLAS by using FindBLAS (here).
I am trying to link OpenBLAS to my c++ project. Here is my CMakeLists.txt.
cmake_minimum_required(VERSION 3.15)
project(my_project)
# source file
file(GLOB SOURCES "src/*.cpp")
# executable file
add_executable(main.exe ${SOURCES})
# link openblas
set(BLA_VENDER OpenBLAS)
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("OpenBLAS found.")
include_directories(${BLAS_INCLUDE_DIRS})
target_link_libraries(main.exe ${BLAS_LIBRARIES})
endif(BLAS_FOUND)
If I run cmake, it runs just find, and outputs OpenBLAS found.. However, if I start to compile the codes (make VERBOSE=1), the library is not linked, so that the codes fail to compile. Here is the error info:
fatal error: cblas.h: No such file or directory
#include <cblas.h>
^~~~~~~~~
compilation terminated.
I installed OpenBLAS successfully. The header files are in /opt/OpenBLAS/include, and the shared libraries are in /opt/OpenBLAS/lib. My OS is ubuntu 18.04.
Any help? Thank you!
Thanks Tsyvarev. I found the problem.
I tried to use message() to print out the variables.
message(${BLAS_LIBRARIES})
Which gives:
/opt/OpenBLAS/lib/libopenblas.so
So the shared library is found.
However, for BLAS_INCLUDE_DIRS, it gives:
message(${BLAS_INCLUDE_DIRS})
CMake Error at CMakeLists.txt:27 (message):
message called with incorrect number of arguments
It turns out that BLAS_INCLUDE_DIRS is not in the FindBLAS variables. So I add the include header files manually:
set(BLA_VENDER OpenBLAS)
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("OpenBLAS found.")
include_directories(/opt/OpenBLAS/include/)
target_link_libraries(main.exe ${BLAS_LIBRARIES})
endif(BLAS_FOUND)
This time it compiles without error. Instead of using include_directories(), you could also try find_path() (check this).

kdev-ruby's CMakeFile.txt requires weird stuff like KF5Config.cmake

I'm trying to compile a Ruby plugin for KDevelop: https://github.com/KDE/kdev-ruby
When I cut a folder called build, cd build, and run cmake .., I get lots of errors:
CMake Error at CMakeLists.txt:13 (include):
include could not find load file:
KDEInstallDirs
CMake Error at CMakeLists.txt:14 (include):
include could not find load file:
KDECMakeSettings
CMake Error at CMakeLists.txt:15 (include):
include could not find load file:
KDECompilerSettings
CMake Error at CMakeLists.txt:16 (include):
include could not find load file:
ECMQtDeclareLoggingCategory
CMake Error at CMakeLists.txt:24 (find_package):
By not providing "FindKF5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "KF5", but
CMake did not find one.
Could not find a package configuration file provided by "KF5" (requested
version 5.15.0) with any of the following names:
KF5Config.cmake
kf5-config.cmake
Add the installation prefix of "KF5" to CMAKE_PREFIX_PATH or set "KF5_DIR"
to a directory containing one of the above files. If "KF5" provides a
separate development package or SDK, be sure it has been installed.
How, on Ubuntu, do I install something that provides KF5Config.cmake? Preferably without rebuilding KDevelop or KDE or Qt5.
KDevelop relies on the development headers for various libraries, and finds them via the accompanying CMake files.
The build also uses CMake modules provided by the extra-cmake-modules package.
You must install that and libkf5config-dev.
The apt-file command might help you find the relevant packages for your distro in these situations.

CMake linking to an import library

I need to link my project to the libmysql.dll dynamic library (I need to do it because I'm building my project as /MDd, reference: https://dev.mysql.com/doc/refman/5.6/en/c-api-building-clients.html)
Now the tricky part is that it is an import library (reference: https://msdn.microsoft.com/en-us/library/d14wsce5.aspx) so there is a libmysql.lib as well.
I'm using CMake for the build:
set(MYSQL_DIR "C:/Program Files/MySQL/MySQL Connector C 6.1"
CACHE PATH "The path to the MySQL C API library")
include_directories(${MYSQL_DIR}/include)
find_library(mysql NAMES libmysql PATHS ${MYSQL_DIR}/lib)
message(STATUS "mysql library: " ${mysql})
CMake finds the library libmysql.lib but when I try to compile I get the following linker error:
LINK : fatal error LNK1104: cannot open file 'mysql.lib'
mysql as you can check above is the name of the CMake variable that contains the path to libmysql.lib.
I have tried to link directly to the .dll but it does not work either, CMake does not find the .dll.
Question
How should I proceed in CMake to link to the import library? Thanks for any help.
You need to use result of find_library() call in target_link_libraries(). In your case it is target_link_libraries(main ${mysql}).

yaml-cpp cmake error, boost files not found

I just downloaded and tried to build yaml-cpp v. 0.5.1, did everything as specified both in the web page and in the install.txt file, but got the following error: CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1138 (message):Unable to find the requested Boost libraries.
Anyone know how to fix it?

"OpenCV" is considered to be NOT FOUND

Linux Flavor: Debian (Crunch Bang)
Problem Occurred: When attempting to build cvblobs with the following command
cd ~/cvblob
cmake .
Error:
CMake Error at cvBlob/CMakeLists.txt:20 (find_package):
Found package configuration file:
/usr/local/share/OpenCV/OpenCVConfig.cmake
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
NOT FOUND.
-- Configuring incomplete, errors occurred!
Well I met a similar problem when I was going with some other open source face detection modules rather than cvblobs.
Actually you will find that before these lines of error-info, there are:
CMake Warning at /usr/local/opencv-2.4.13/cmake/OpenCVConfig.cmake:163 (message):
Found OpenCV Windows Pack but it has not binaries compatible with your configuration.
You should manually point CMake variable OpenCV_DIR to your build of OpenCV library.
Call Stack (most recent call first):
CMakeLists.txt:57 (find_package)
CMake Warning at CMakeLists.txt:57 (find_package):
Found package configuration file:
/usr/local/opencv-2.4.13/cmake/OpenCVConfig.cmake
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND.
So you may notice that it asks you to manually point out the directory of you build version of OpenCV library.
For me, my source codes are at
/usr/local/opencv-2.4.13/
but I make and install my release build of OpenCV at
/usr/local/opencv-2.4.13/release/
so I use:
cmake -D OpenCV_DIR=/usr/local/opencv-2.4.13/release/ ..
and everything works:)
When I compile a program that use OpenCV lib, vision 2.4.8, occurs the similar error, when I point manually Opencv_DIR path to opencv/build ,visio 3.1.0, error occurred like you.
Then I point Opencv_DIR path to opencv/build whose vision is same to the program used. It works.
One of the reason could be the another OpenCV package in another path, that you had installed before. In my case, I had already installed OpenCV for Python in Anaconda package, and the CMake always wanted to refer me to that package.
I simply added:
set(OpenCV_FOUND 1)
to my CMakeList.txt file, this command simply override the other package you may had installed. The final version of CMakeList file which is working for me would be this:
set( OpenCV_FOUND 1 )
find_package(OpenCV 2.4.13 REQUIRED PATHS "C:/opencv")
set(SOURCE_FILES main.cpp)
add_executable(OpenCV_Test ${SOURCE_FILES})
Note:
1- I am using the CMakeList.txt file for Clion IDE
2- I am using it under windows. Probably you may set the relevant path if you use other OS
3- You need also change the OpenCV version if you use other version