I am trying to build a project using an external library, but the system keeps thinking it needs to use the library inside usr/lib which is broken. I wish to instead use the library that is built within the address: /home/CMake-hdf5-1.8.18/build/HDF5-1.8.18-Linux/HDF_Group/HDF5/1.8.18/include. This is the CMakeLists.txt. My intended solution are the two lines under #Add hdf5 library.
cmake_minimum_required(VERSION 2.8.3)
project(scan_to_cloud_converter)
# List C++ dependencies on ros packages
set( ROS_CXX_DEPENDENCIES
roscpp
pcl_ros
pcl_conversions)
# Find catkin and all required ROS components
find_package(catkin REQUIRED COMPONENTS ${ROS_CXX_DEPENDENCIES})
find_package(PCL REQUIRED QUIET)
# Set include directories
include_directories(include ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})
# Declare info that other packages need to import library generated here
catkin_package( )
#Create node
add_executable( scan_to_cloud_converter_node
src/scan_to_cloud_converter_node.cpp
src/scan_to_cloud_converter.cpp )
#Add hdf5 library
link_directories(/home/CMake-hdf5-1.8.18/build/HDF5-1.8.18-Linux/HDF_Group/HDF5/1.8.18/include)
target_link_libraries(scan_to_cloud_converter_node libhdf5)
# No need to link against pcl (using header only libraries)
target_link_libraries( scan_to_cloud_converter_node ${catkin_LIBRARIES})
add_dependencies(scan_to_cloud_converter_node ${catkin_EXPORTED_TARGETS})
#Install node
install(TARGETS scan_to_cloud_converter_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
This is the error message I am still getting however:
make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/hdf5/serial/lib/libhdf5.so', needed by '/home/catkin_ws/devel/lib/scan_to_cloud_converter/scan_to_cloud_converter_node'. Stop.
I've done research on this error and it is because it is still looking into /usr/lib, and there is no library libhdf5.so there as the symlink is broken. So how do I get it to instead look at the other address for that library?
For linking a cmake project with hdf5, I suggest to use the find_package
feature of cmake.
Include the line
find_package(HDF5)
in CMakeLists.txt
.
Then, you can use target_link_libraries(your_lib ${HDF5_C_LIBRARIES})
to link appropriately. The include directories are stored in ${HDF5_INCLUDE_DIRS}
.
Now, to the point of your question that is to select a specific HDF5 location, issue the command
export HDF5_ROOT=/home/CMake-hdf5-1.8.18/build/HDF5-1.8.18-Linux/HDF_Group/HDF5/1.8.18
before issuing cmake. You need to have a clear cache for this to work:
rm -r CMakeCache.txt CMakeFiles