0

I have been sitting on this for a while now and really do not understand what is going on. I have the following problem with cmake and armadillo/lapack/blas:

I try to download armadillo with cmake, compile it and then link it to my program.

However, while I can download, compile it etc. I have troubles linking it to my program.

I get the following error when linking to an executable: undefined reference to `dgemv_' So I know that this is a lapack/blas thing, but I cannot figure out what is wrong.

The relevant parts in my CMakeLists.txt are below. I would be very happy if someone could help me. I am close to eating my keyboard out of frustration.

ExternalProject_Add(ArmadilloDownload
    PREFIX ${LIBRARY_OUTPUT_PATH}/armadillo-7.100.3
    DOWNLOAD_COMMAND wget http://sourceforge.net/projects/arma/files/armadillo-7.100.3.tar.xz
    CONFIGURE_COMMAND tar -xf ../armadillo-7.100.3.tar.xz -C ../ArmadilloDownload  --strip-components=1
    BUILD_IN_SOURCE 1
    BUILD_COMMAND cmake .
    INSTALL_COMMAND make
    UPDATE_COMMAND ""
    )

set(Armadillo_DIR ${LIBRARY_OUTPUT_PATH}/armadillo-7.100.3/src/ArmadilloDownload)
set(ARMADILLO_LIBRARY ${Armadillo_DIR}/libarmadillo.so)
set(ARMADILLO_INCLUDE_DIR ${Armadillo_DIR}/include/)
include_directories(${ARMADILLO_INCLUDE_DIR})
set(GCC_ARMADILLO_LINK_FLAG "-O1 -llapack -lblas")
SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_ARMADILLO_LINK_FLAG}")
SET(CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_SHARED_LINKER_FLAGS} ${GCC_ARMADILLO_LINK_FLAG}")
DUWUDA
  • 342
  • 5
  • 13
  • 1
    You shouldn't specify the linker flags that way. Check out how CMake works, especially `target_link_libraries`. – usr1234567 Jul 06 '16 at 18:30
  • I thought that how you can set linker flags (see [here](http://stackoverflow.com/questions/11783932/how-to-add-linker-or-compile-flag-in-cmake-file)). I put those flags into the `traget_link_library` but that also doesn't work (same error) – DUWUDA Jul 07 '16 at 01:43
  • @usr1234567 Now I also tried to use `target_compile_options` which also does not work with `target_compile_options(program PRIVATE -O1 -llpack -lblas)` – DUWUDA Jul 07 '16 at 02:52
  • @usr1234567 both my exe and shared library have the `-O1 --llpack -blas` flags, still the same error when compiling – DUWUDA Jul 07 '16 at 08:57

1 Answers1

1

I should have used target_link_library for setting the library flags and not SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_ARMADILLO_LINK_FLAG}")

So using works

target_link_libraries(exe
    customlib1
    customlib2
    -O2 blas lapack
    )
DUWUDA
  • 342
  • 5
  • 13