skip to Main Content

If I install the same CMake-based package (cxxopts) with the same compiler (gcc12) on two different Unix machines (CentOS & MacOS), one time I get a prefix/lib and the other a prefix/lib64 directory.

Is there a way to predict what the lib directory is going to be?

2

Answers


  1. The installation directory is determined from two parts.

    • All files will be installed within the install directory determined by CMAKE_INSTALL_PREFIX. This variable can be set by the user when configuring the build and projects should respect that choice. The default on Linux for this is usually /usr/local, but you can set it to instead install to, say, a subfolder within your home directory.
    • The directory structure within the install directory is usually determined by the project itself, with only limited configurability from the outside. Whether libraries get put into the lib or lib64 subdirectory therefore depends on the individual project and there is no hard rule for predicting the directory layout from the outside.

    The exact directory structure within the install directory is determined by the INSTALL commands given to CMake, in particular the DESTINATION field. Most projects follow common conventions here, but you will need to consult a project’s documentation or its CMake files to figure out the exact layout.

    The relevant INSTALL command for cxxopts can be found here.
    Note that cxxopts uses CMake’s GNUInstallDirs module to configure the directories, which follows the common GNU/Linux conventions. That module is also responsible for the distinction between lib and lib64 here.

    Login or Signup to reply.
  2. How does CMake decide to make a lib or lib64 directory for installations?

    It’s not so much up to CMake as it is up to the maintainers of a project where a target gets installed to (see the DESTINATION parameter of the install(...) command).

    cxxopts uses GNUInstallDirs, which is a helper module provided by CMake defining conventional installation locations for different types of things. See its CMakeLists.txt (include(GNUInstallDirs)) and its cxxopts.cmake file (install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})).

    From the GNUInstallDirs docs:

    LIBDIR
    object code libraries (lib or lib64)


    Is there a way to predict what the lib directory is going to be?

    If the project uses GNUInstallDirs, yes. From the CMake source code:

    Override this default ‘lib’ with ‘lib64’ iff:

    • we are on Linux system but NOT cross-compiling
    • we are NOT on debian
    • we are NOT building for conda
    • we are on a 64 bits system

    reason is: amd64 ABI: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
    For Debian with multiarch, use lib/${CMAKE_LIBRARY_ARCHITECTURE} if
    CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
    and CMAKE_INSTALL_PREFIX is "/usr".
    See http://wiki.debian.org/Multiarch

    If you want to do a check at configure time of what this is, then check the CMAKE_INSTALL_LIBDIR variable. Ex. if("${CMAKE_INSTALL_LIBDIR}" STREQUAL "lib64") ....

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search