mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
These are instructions for installing the "mxlib" c/c++ library. This is my personal library which I have built up over many years. Along the way I have tried to keep it organized and documented. I have installed it on several different linux systems (running CentOS or Ubuntu). Installation on Mac O/S is also possible using Conda.
The below instructions were updated in June 2022 after a fresh install on Ubuntu 22.04.
This is the list of the other libraries and code-bases mxlib depends on. I usually install these from scratch to ensure maximum optimization (though I have little to no quantitative evidence that it matters), but you can probably manage most of these from the O/S package manager. You will need to make sure to install the dev
packages.
Alternatively, see the next section for quickstart instructions using the conda package manager (part of miniconda or Anaconda) on Linux or macOS.
scl enable devtoolset-7 bash
. To enable it for a user add this to .bashrc:
libboost-all-dev
.The relevant header files for each library need to be accessible to the compiler, either in a standard location or in one you specify when compiling your programs.
The conda package manager contains packages for all of mxlib's external dependencies (not including vendored libraries, shipped under source/vendor/). This means setting up a correct build environment on macOS or Linux – even in a cluster environment, where you may not have root access – is straightforward. (To do: CUDA support with conda.)
Once you have installed conda (either miniconda or Anaconda is fine), you will create and activate an environment to use mxlib with.
The install process is tested with conda-forge packages, which you may not be using by default. (Installing them in the mxlib_env environment won't cause conflicts with any other environments you may have.)
You may see the message: "To make your changes take effect please reactivate your environment." That would be "conda deactivate" followed by "conda activate mxlib_env".
If all went well, you should now be able to build mxlib:
Now mxlib headers and libraries are in $CONDA_PREFIX/include and $CONDA_PREFIX/lib and should be found by default as long as "conda activate mxlib_env" is always run after you open a new terminal and before you compile things that use mxlib.
Mxlib includes a systems to track its git version, using the SHA1 hash. This, in principle, allows any results to be tagged with the version of the library used to generate them. The goal is to always be able to restore the code to a given point so that previous results can be reproduced. The library will issue a warning at compile time if there are any modifications to it that aren't yet committed, meaning that they aren't trackable.
$HOME
, you will want to invoke make
with make PREFIX=/path/to/libraries
(where /path/to/libraries
is the path to the folder containing lib
and include
folders for things like levmar and Eigen.) Alternatively, set that variable permanently following the steps below.make setup
. This will create three Makefiles in local/
for you to customize.local/
directory only. Some options are:?=
in the files in mk/
can be overridden in the corresponding local/
one. The files in local/
are not tracked in git and editing them will not cause compile warnings.$HOME
to something else, set PREFIX=
in local/Common.mk
.USE_BLAS_FROM
can be set to mkl
, ATLAS
, or Accelerate
(macOS only). You may also need to override BLAS_INCLUDES
, BLAS_LDFLAGS
, and/or BLAS_LDLIBS
to set paths and flags. (See mk/MxApp.mk
for examples.)mxlib
by running make
at the top level. mxlib
with make install
. sudo
may be required depending on the PREFIX
. Possibly sudo -E
.Once mxlib is built and installed, set the $MXMAKEFILE
variable in your shell (and/or shell profile files):
You can then build a single .cpp program, let's say "myProgram.cpp", with the following line
To install it, you need to give make
a hint about what is to be installed. The command is
This installs the myProgram
binary to $PREFIX/bin
(which is $HOME/bin
unless you have set PREFIX
in one of the local/
Makefiles).
For more complicated applications, you can create a local Makefile
which specifies additional objects with OTHER_OBJS
, and finally includes MxApp.mk
.