0

I am trying to build Armadillo C++ library (version 6.6) and it does build fine. My problem, however, is that I have separately downloaded the source code for OpenBLAS and built that. I want Armadillo to use the OpenBLAS that I built locally, and i'd like it to statically link it into the Armadillo library that is produced.

So,

  1. How do i tell the Armadillo CMake to use a specific OpenBLAS?
  2. How do i tell the Armadillo CMake to statically link the above OpenBLAS so it produces a libarmadillo that contains my OpenBLAS in it?
Smern
  • 18,746
  • 21
  • 72
  • 90
Dan S
  • 121
  • 1
  • 5

2 Answers2

1

If you have installed OpenBLAS from source, it is at a non-standard location (for me it is at /opt/OpenBLAS) and have a non-standar name (OpenBLAS). Therefore it is hard for cmake to found it, in order to sove the problem please edit the file at your_sources_dir/cmake_aux/Modules/ARMA_FindOpenBLAS.cmake as follows:

set(OpenBLAS_NAMES)
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblaso)
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblasp)
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblas )
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} OpenBLAS )

set(OpenBLAS_TMP_LIBRARY)
set(OpenBLAS_TMP_LIBRARIES)


foreach (OpenBLAS_NAME ${OpenBLAS_NAMES})
  find_library(${OpenBLAS_NAME}_LIBRARY
    NAMES ${OpenBLAS_NAME}
    PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/local/lib64 /opt/local/lib /opt/OpenBLAS/lib
    )

  set(OpenBLAS_TMP_LIBRARY ${${OpenBLAS_NAME}_LIBRARY})

  if(OpenBLAS_TMP_LIBRARY)
    set(OpenBLAS_TMP_LIBRARIES ${OpenBLAS_TMP_LIBRARIES} ${OpenBLAS_TMP_LIBRARY})
  endif()
endforeach()


# use only one library                                                                                                                                                                                                                       

if(OpenBLAS_TMP_LIBRARIES)
  list(GET OpenBLAS_TMP_LIBRARIES 0 OpenBLAS_LIBRARY)
endif()


if(OpenBLAS_LIBRARY)
  set(OpenBLAS_LIBRARIES ${OpenBLAS_LIBRARY})
  set(OpenBLAS_FOUND "YES")
else()
  set(OpenBLAS_FOUND "NO")
endif()


if(OpenBLAS_FOUND)
  if (NOT OpenBLAS_FIND_QUIETLY)
    message(STATUS "Found OpenBLAS: ${OpenBLAS_LIBRARIES}")
  endif()
else()
  if(OpenBLAS_FIND_REQUIRED)
    message(FATAL_ERROR "Could not find OpenBLAS")
  endif()
endif()


# mark_as_advanced(OpenBLAS_LIBRARY)

Then proceed with the regular installation of armadillo using cmake.

I hope this suggestion helps.

0

If you are building from source (as recommended) check the directory cmake_aux.

The ARMA_FindOpenBLAS.cmake file within this directory searches for the OpenBLAS library.

Modifying search paths to point to the desired OpenBLAS library's location did the trick for me.

For static linking, you make have to modify the files build.make, depend.make and link.txt in CMakeFiles/armadillo.dir

I know this is a very patchy solution.

If there is a better solution, I would like to know.