How to install Armadillo library, the easy way!

Back to May, we have written a post about the procedure we need to follow in case we want to use the Armadillo library in Ubuntu. It works, but in this post, I would suggest an even easier way to do it.

The solution called Conan, the C/C++ Package Manager. It can be used for any third-party libraries, either using the official JFrog Conan Center or users’ JFrog bintray.

Let’s start first by installing Conan. Yes, it’s dead easy. We use pip3, how?

pip3 install conan

in case you are in a system that hosts both Python2 and Python3.

Then you get your chance to find the package in question into the Conan Center. For Armadillo library this is not the case. We no need to worry though because Darlan Cavalcante Moreira has uploaded it in the bintray. Happy days, I say.

First thing first, we need to add his remote bintray package recipe in our system like that:

conan remote add darcamo-bintray https://api.bintray.com/conan/darcamo/cppsim

Next, we need to create the corresponding conan file (conanfile.txt) indicating the package, the version, the repository and the intended use, in our case cmake.

[requires]
armadillo/10.1.0@darcamo/stable

[generators]
cmake

We save that file in our project too. If you are using Ubuntu 18 you cannot use directly the compiled packages because have not been prepared for GCC version 7. This is not a show stopper though cause we can build them and deliver the requested functionality without any issues. How? Using the following command:

conan install . -s build_type=Debug --install-folder=cmake-build-debug --build=missing

In my case, I forward the outcome in the cmake-build-debug (i.e. CLion) as well as I request to build the missing packages, as was explained before.

What comes last? Obviously the bit of using it without caring for the technicalities. Cmake is as always our friend, and a text like the following makes the trick:

cmake_minimum_required(VERSION 3.16)
project(someExperiments)

if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
else()
    message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()

set(CMAKE_CXX_STANDARD 20)

add_executable(experiment armadillo.cpp)
target_link_libraries(experiment ${CONAN_LIBS})

What a joy. Yes, this was not supposed to be an exhaustive guide. We just scratched the surface of an exciting tool to use. You can find a lot of online guidance as well as using the CLion plugin in case that you have this lovely IDE.

Have fun!