Static library under Linux contains undefined symbol

The static library built from source HEAD of current default branch(9.900.x) under Linux contains undefined symbol, which later results in an "undefined symbol" error when linking with this library

Environment

  • A fresh Archlinux 20200719 installation, with the following packages installed:

    pacman -Syu lapack openblas superlu
  • GCC 10.1.0, installed through pacman -Syu base-devel

  • CMake 3.18.0, installed through pacman -Syu cmake

Steps to reproduce

  1. Build Armadillo static library
    cd ~ && git clone https://gitlab.com/conradsnicta/armadillo-code.git
    mkdir -p ~/armadillo-build && cd ~/armadillo-build
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/armadillo-install -DBUILD_SHARED_LIBS=OFF -DDETECT_HDF5=OFF ~/armadillo-code
    cmake --build . --config Release && cmake --install . --config Release
  2. Try to compile the example ./examples/example1.cpp
    g++ -g -std=c++11 -o example1 -isystem ~/armadillo-install/include -l:libarmadillo.a -L ~/armadillo-install/lib/ ~/armadillo-code/examples/example1.cpp

Expected behavior

The above g++ command shall build the example file successfully.

Actual behavior

The above g++ command emits the following error:

usr/bin/ld: /tmp/ccFu4xfz.o: in function `TLS wrapper function for arma::arma_rng_cxx11_instance':
example1.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x21): undefined reference to `arma::arma_rng_cxx11_instance'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `double arma::blas::dot<double>(unsigned long long, double const*, double const*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_blas.hpp:167: undefined reference to `wrapper2_ddot_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::lapack::getrf<double>(int*, int*, double*, int*, int*, int*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_lapack.hpp:33: undefined reference to `wrapper2_dgetrf_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_blas.hpp:36: undefined reference to `wrapper2_dgemv_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::lapack::trtri<double>(char*, char*, int*, double*, int*, int*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_lapack.hpp:86: undefined reference to `wrapper2_dtrtri_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::lapack::potrf<double>(char*, int*, double*, int*, int*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_lapack.hpp:317: undefined reference to `wrapper2_dpotrf_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::lapack::potri<double>(char*, int*, double*, int*, int*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_lapack.hpp:383: undefined reference to `wrapper2_dpotri_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::lapack::getri<double>(int*, double*, int*, int*, double*, int*, int*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_lapack.hpp:70: undefined reference to `wrapper2_dgetri_'
/usr/bin/ld: /tmp/ccFu4xfz.o: in function `void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
/home/gnaggnoyil/armadillo-install/include/armadillo_bits/translate_blas.hpp:62: undefined reference to `wrapper2_dgemm_'
collect2: 错误:ld 返回 1

Additional Info

There seems to be some incorrectly generated undefined symbol in the generated libarmadillo.a. Running nm -C ~/armadillo-install/lib/libarmadillo.a gives the output as shown in the attachment out.txt.

Also, if I remove the -DBUILD_SHARED_LIBS=OFF option, generate shared libarmadillo.so.9.900.2 library, and link this shared library with -l:libarmadillo.so.9.900.2 option in the g++ command above, the example1.cpp can be compiled and built successfully without problems.

Edited by gnaggnoyil