In my ROS package I would like to use a last stable version of Eigen which is 3.3.4.
However when I check my version into package by EIGEN_MAJOR_VERSION, EIGEN_WORLD_VERSION, EIGEN_MINOR_VERSION I have got a 3.3.90.
In my CMakeList:
find_package(Eigen3 REQUIRED)
include_directories(include ${EIGEN3_INCLUDE_DIR}
find_package for specific version does not exists.
So how can I change the version? I downloaded Eigen from official github. I built it bysudo make install I got a log that everything is updated.
Up-to-date: /usr/local/include/eigen3/...
Thanks.
The answer was very very simply, when I clone from githube it was the newest version...
You can find the last stable version on official Eigen web. Then download, and follow the INSTALL instructions. So create build folder, cmake src_directory, sudo make install which will copy all headers into /usr/include/eigen3/.. then you can use version which you compile.
I suppose that as Eigen has only .h files you don't really need compile lib only do find_package(Eigen3 REQUIRED PATH ...) but I didn't test this solution.
Related
I need to build a C++ program with CMake but it cannot find Boost.
I'm getting the following error no matter what solutions I've found online for other people with this problem...
-- Compiling with C++ standard: 17
CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least
version "1.68.0")
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
CMakeLists.txt:49 (find_package)
This is the part of my CMakeLists.txt looking for Boost
if(NUMCPP_NO_USE_BOOST)
target_compile_definitions(${ALL_INTERFACE_TARGET} INTERFACE -DNUMCPP_NO_USE_BOOST)
else()
find_package(Boost 1.68.0 REQUIRED)
target_link_libraries(${ALL_INTERFACE_TARGET} INTERFACE Boost::boost)
endif()
I have installed boost with sudo apt-get install libboost-all-dev and a few other apt-get options. I always see 0 upgraded, 0 newly installed, 0 to remove after running.
$ whereis boost
boost: /usr/include/boost
Do I need to specify it in the cmake .. line in the terminal somehow?
Assuming that you've successfully installed boost in the default directory, and CMake has access to those directories, probably the problem (as #drescherjm mentioned) is in the version of the Boost you've installed (sometimes the packages provided by apt-get are relatively old).
On the other hand it can also be that CMake doesn't have the installation directory in its search path.
The following steps might be a good place to start:
Check the version of the Boost installed: How to determine the Boost version on a system? and here
If the version installed by apt-get satisfies the project requirement, it seems for some reason CMake didn't include a directory of installation to its searching path. If that's the case, skip to the step 3.
If it's lower than your project requires, build it from source (right now 1.80 is available) to your preferred directory. If you need the libraries which need to be built, check this tutorial.
Tell CMake where to search for built Boost. See here: Cmake doesn't find Boost
I hope this reply is not too off-topic. I suggest you consider using a package manager such as conan or vcpkg.
An example of using conan to use external dependencies.
1. Create conanfile.txt
It should have the following content:
[requires]
boost/1.80
[generators]
CMakeDeps
CMakeToolchain
2. Download your dependencies
mkdir build && cd build
conan install .. --build=missing
conan build ..
The last command is optional and can be changed with:
cmake -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ..
Benefits:
You don't need to "mess" your system with different libraries
Transitional dependencies are handled automatically
The build process is reproducible
I am trying to install libraries like eigen, sharkMl, xtensor, and others in VSCode for C++.
Please if anyone can help me to know the right way to do that.
All of these libraries use CMake for their build system so what I do is use CMake as my build system. My favorite way to do this is to use the libraries build systems to install them and then inlcude them with cmakes find_package function. This you can do by cloning the git repository for the library then build it and install it with cmake. On linux you do this by:
git clone https://gitlab.com/libeigen/eigen.git
cd eigen
mkdir build
cd build
cmake ..
sudo make install
VSCode has good integration for cmake so if you have the C/C++ Extension pack you will be able to build with cmake. In your project folder make a CMakeLists.txt file and add the packages you want:
add_executable(main main.cpp)
find_package(Eigen3 3.4 NO_MODULE)
target_link_libraries(main Eigen3::Eigen)
(This example assumes the main cpp file is main.cpp and creates an executable called main) Then when you press ctr+shift+p and perform CMake: Configure you can select your compiler and build the executable.
The library I am trying to include is jsoncpp. I am having serious trouble with this. I used the home-brew install for this library, which is brew install jsoncpp (brew install is unix version of linux sudo-apt get). Normally homebrew installs stuff to my path, so I can just use it. I am going off of this example here.
#include <json/json.h>
Returns an error of 10: fatal error: 'json/value.h' file not found.
I am using cmake because CLion automatically sets it up. Right now it is very basic:
#CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(Read_JSON)
set(CMAKE_CXX_STANDARD 17)
add_executable(Read_JSON main.cpp)
However, for some reason jsoncpp cannot be found. How can I include this library in my project?
You can use in CMake FetchContent capability.
Jsoncpp is available via git repository on GitHub
Here is example how I made with googletest:
https://github.com/adamvm/hello/blob/master/CMakeLists.txt
You need just substitute proper addresses and names
On mac install with command.
brew install osrf/simulation/ignition-fuel-tools2
In Ubuntu (since 18.04) you need to install libjsoncpp-dev[1] package:
sudo apt install libjsoncpp-dev
[1] https://packages.ubuntu.com/search?keywords=libjsoncpp-dev
I know how to link GDAL with a C++ application using CMake. The procedure is summarized hereafter in two steps: (1) Installing the dependency on the system and (2) linking it to the C++ application (see here for more details).
Install GDAL (here on Ubuntu 18.04)
Add the PPA to the sources: sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
Update: sudo apt-get update
Install GDAL and its development files: sudo apt-get install gdal-bin libgdal-dev
Test the installation: gdalinfo --version
Link GDAL with the C++ application using CMake:
# find system installed GDAL package with predefined CMake variable for finding GDAL
find_package(GDAL REQUIRED)
...
# Specify location of GDAL header files
include_directories( include ${GDAL_INCLUDE_DIRS})
...
# Specify GDAL libraries to link your cpp executable target against
target_link_libraries( your_cpp_executable_target_name ${GDAL_LIBRARIES})
What is the most convenient way to avoid the user to perform the manual installation of the dependency? That is, how to ensure that the missing dependency will not stop the configuration, and download/build the dependency if not found on the system?
For managing the Boost dependency, I used the CMake ExternalProject feature with a Superbuild pattern, and I think a similar approach should be relevant for managing GDAL dependency. However, I am very new at modern CMake, and I struggle adapting this CMake project handling the Boost dependency to also manage a GDAL dependency.
Any general or step-by-step directions to help doing (or good reasons not to do so) would be helpful.
After installing packages with vcpkg, help text is shown, eg...
The package fmt:x64-windows provides CMake targets:
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt fmt::fmt-header-only)
... for the varying instructions needed for using them with CMake. Where do you get this information from if you want to recall it in the future and didn't write it down? Some libraries have more involved instructions than the above.
You can find the help text in files called 'usage'.
You can locate them in either in ports directory or if you are interested only for your packages, then they are in installed. You can search for them with the following command:
# VCPKG_ROOT denotes where is vcpkg installed
$ find $VCPKG_ROOT . -name usage
installed/x64-linux/share/openssl/usage
installed/x64-linux/share/gtest/usage
However some packages, including fmt, are not providing this information in a specific file, they are providing only targets. They are stored in $VCPKG_ROOT/installed/<YOUR_ARCHITECTURE>/share/fmt/fmt-targets.cmake.
vcpkg is then printing a list of targets after the installation. I don't know if there exists a better solution then finding the <package>-targets.cmake files and checks the content.
$ find $VCPKG_ROOT/installed -name *-targets.cmake
installed/x64-linux/share/cxxopts/cxxopts-targets.cmake
installed/x64-linux/share/fmt/fmt-targets.cmake
So if you combine these two techniques, you should be able to find all the information that vcpkg is printing after installation.
Just run the command vcpkg install again.
.\vcpkg.exe install fmt
Computing installation plan...
The following packages are already installed:
fmt[core]:x64-windows -> 8.0.1
Package fmt:x64-windows is already installed
Restored 0 packages from **\AppData\Local\vcpkg\archives in 155.9 us. Use --debug to see more details.
Total elapsed time: 58.04 ms
The package fmt provides CMake targets:
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt)
# Or use the header-only version
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE fmt::fmt-header-only)