Skip to content

Tools for the mmg libraries users

Algiane Froehly edited this page Feb 23, 2016 · 11 revisions

I/ Link with the mmg libraries

By default, the make install command installs the libraries into the /usr/local/lib directory. The header files are located into the /usr/local/include directory.

1) Link with the mmg libraries using CMake

You can use:

If the package fails, you can help it by:

  • setting the MMG_DIR environment variable to your mmg directory path:
export MMG_DIR=<your_mmg_directory_path>
  • or setting the MMG_DIR CMake variable to your mmg directory path:
SET(MMG_DIR <your_mmg_directory_path>)

FindMmg.cmake package

The FindMmg.cmake package defines the MMG_INCLUDE_DIR and the MMG_LIBRARY variables.
To link a program named YOUR_TARGET with the mmg library using CMake, just add the following lines in your CMakeLists.txt:

INCLUDE(FindMmg.cmake)
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIR})
TARGET_LINK_LIBRARIES( ${YOUR_TARGET} ${MMG_LIBRARY})

Don't forget to include the mmg library headers to your program:

#include "mmg/libmmg.h"

FindMmg2d.cmake package

The FindMmg2d.cmake package defines the MMG2D_INCLUDE_DIR and the MMG2D_LIBRARY variables.
To link a program named YOUR_TARGET with the mmg2d library using CMake, just add the following lines in your CMakeLists.txt:

INCLUDE(FindMmg2d.cmake)
INCLUDE_DIRECTORIES(${MMG2D_INCLUDE_DIR})
TARGET_LINK_LIBRARIES( ${YOUR_TARGET} ${MMG2D_LIBRARY})

Don't forget to include the mmg2d library headers to your program:

#include "mmg/mmg2d/libmmg2d.h"

FindMmgs.cmake package

The FindMmgs.cmake package defines the MMGS_INCLUDE_DIR and the MMGS_LIBRARY variables.
To link a program named YOUR_TARGET with the mmgs library using CMake, just add the following lines in your CMakeLists.txt:

INCLUDE(FindMmgs.cmake)
INCLUDE_DIRECTORIES(${MMGS_INCLUDE_DIR})
TARGET_LINK_LIBRARIES( ${YOUR_TARGET} ${MMGS_LIBRARY})

Don't forget to include the mmgs library headers to your program:

#include "mmg/mmgs/libmmgs.h"

FindMmg3d.cmake package

The FindMmg3d.cmake package defines the MMG3D_INCLUDE_DIR and the MMG3D_LIBRARY variables.
To link a program named YOUR_TARGET with the mmg3d library using CMake, just add the following lines in your CMakeLists.txt:

INCLUDE(FindMmg3d.cmake)
INCLUDE_DIRECTORIES(${MMG3D_INCLUDE_DIR})
TARGET_LINK_LIBRARIES( ${YOUR_TARGET} ${MMG3D_LIBRARY})

Don't forget to include the mmg3d library headers to your program:

#include "mmg/mmg3d/libmmg3d.h"

2) Link with the mmg libraries in command line

We supposed in the following that:

  • you want to compile a program with only one file, the main.c file;
  • the mmg libraries are installed in the usr/local directory (default configuration);
  • the scotch library is installed in the <SCOTCH_PATH> directory.

Here we use the example of the mmg3d library.
You must compile specifying:

  • the mmg3d include directory with the -I option;
  • the mmg3d library location with the -L option;
  • the mmg3d library name with the -l option.
 gcc main.c -I/usr/local/include/ -L/usr/local/lib -L<SCOTCH_PATH> -lmmg3d -lscotch -lscotcherr -lm

Note that mmg uses the math library thus, it may be needed to link with it (-lm option). If you have build mmg without scotch, just remove the variables related to it:

 gcc main.c -I/usr/local/include/ -L/usr/local/lib -lmmg3d -lm

It may be needed to add the path toward the libraries directory to your LD_LIBRARY_PATH environment variable:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

Don't forget to include the mmg3d library headers to your program:

#include "mmg/mmg3d/libmmg3d.h"

II/ Usage examples

You can find examples of the use of the mmg libraries in the [libexamples][libexamples] subfolder (see the projects source tree section of the wiki for the description of the libexamples directory).

Clone this wiki locally