Build fails with NUMA installed to non-standard location [Linux]

Issue #540 resolved
Former user created an issue

The source/CMakeLists.txt file calls find_package(Numa) which in turn uses the source/cmake/FindNuma.cmake configuration. It finds the NUMA library which, in my case, is installed into a non-standard directory: I have a CMake project where both the NUMA and the x265 libraries are built using ExternalProject_Add and are installed into a subdirectory under my project root.

find_package() correctly saves the paths into the CMake variables defined in source/cmake/FindNuma.cmake: the include directory gets stored in NUMA_INCLUDE_DIR and the library directory in NUMA_LIBRARY_DIR.

The main CMake config file then proceeds on to checking whether the NUMA library was found and tries to make further settings:

if(NUMA_FOUND)
  link_directories(${NUMA_LIBRARY_DIR})
  list(APPEND CMAKE_REQUIRED_LIBRARIES numa)
  check_symbol_exists(numa_node_of_cpu numa.h NUMA_V2)
  ...
endif()

The check_symbol_exists() function, however, errors out because it can't include numa.h as it doesn't know where to find it.

Furthermore list(APPEND CMAKE_REQUIRED_LIBRARIES numa) breaks subsequent check_symbol_exists() calls because now the NUMA library is added to the link steps but the linker doesn't know where to find the library. Specifically it breaks the check_symbol_exists(strtok_r "string.h" HAVE_STRTOK_R) check which in turn breaks the whole build with an error "'char strtok_r(char, const char, char*)' was declared 'extern' and later 'static'".

Not finding the NUMA library also breaks subsequent check_cxx_compiler_flag() checks which also try to use the -lnuma command line option behind the scenes. An example error:

/home/linuxbrew/.linuxbrew/bin/c++   -DCC_HAS_NO_STRICT_OVERFLOW    -rdynamic CMakeFiles/cmTC_2b550.dir/src.cxx.o  -o cmTC_2b550  -lnuma 
/usr/bin/ld: cannot find -lnuma

Both problems can be fixed by telling the compiler and the linker where to find the NUMA header and library files. Within the if(NUMA_FOUND) block, before calling check_symbol_exists(numa_node_of_cpu numa.h NUMA_V2) these two lines made the build successfully complete for me:

list(APPEND CMAKE_REQUIRED_INCLUDES ${NUMA_INCLUDE_DIR})
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-L${NUMA_LIBRARY_DIR}")

Comments (1)

  1. Aruna Matheswaran

    Set the NUMA include and library directories.

    Make sure that

    check_symbol_exists(numa_node_of_cpu numa.h NUMA_V2)

    finds the numa.h file and libnuma in case NUMA is installed into a non-standard directory. If find_package(Numa) found the library, the header and library directories are stored in the NUMA_INCLUDE_DIR and NUMA_LIBRARY_DIR CMake variables.

    Fixes Issue #540.

    → <<cset 479b96e84e98>>

  2. Log in to comment