2

I downloaded and built (seemingly correctly) the relevant BLAS and CBLAS libraries (from netlib.org/blas) in my Linux Fedora environment. The result of this was a blas_LINUX.a file, which I renamed libblas.a and copied to \usr\local\lib, and a cblas.h file which I copied to \usr\include. I subsequently tried referencing this in a CMakeList.txt file in a CLion project. The file is as follows:

project(test C)
cmake_minimum_required(VERSION 3.10)

set(CMAKE_C_STANDARD 99)

include_directories(include)

add_executable(${PROJECT_NAME} src/main.c)

find_library(blas libblas.a /usr/local/lib)
MESSAGE(STATUS "CBLAS location is: " ${blas})

target_link_libraries(${PROJECT_NAME} ${blas})

Going by the message that cmake produces when reloaded, the cblas library seems to get found fine. However when I try and run my application, I get the following linker error message:

undefined reference to `cblas_dgemm`

Following are the contents of my main.c file

#include <stdio.h>
#include <stdlib.h>

#include <cblas.h>

int main(int arg, char *args[]) {

  .
  .
  .

    printf("Processing cblas_dgemm matrix multiplication.\n");
    cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, N, N, N, alpha, A[0], N, B[0], N, beta, C[0], N);

  .
  .
  .
    return 0;
}

I'm not entirely sure where I'm going wrong here. I'm very new using cmake, and I'm going around in circles trying to figure out what the problems is, when searching online. Any pointers in the right direction would be greatly received, and appreciated.

Ammendment (CMakeOutput.txt is as follows)

The system is: Linux - 5.4.8-200.fc31.x86_64 - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /usr/bin/cc 
Build flags: 
Id flags:  

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"

The C compiler identification is GNU, found in "/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/3.15.3/CompilerIdC/a.out"

Determining if the C compiler works passed with the following output:
Change Dir: /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_3ac25/fast && gmake[1]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_3ac25.dir/build.make CMakeFiles/cmTC_3ac25.dir/build
gmake[2]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_3ac25.dir/testCCompiler.c.o
/usr/bin/cc    -o CMakeFiles/cmTC_3ac25.dir/testCCompiler.c.o   -c /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_3ac25
/home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3ac25.dir/link.txt --verbose=1
/usr/bin/cc      -rdynamic CMakeFiles/cmTC_3ac25.dir/testCCompiler.c.o  -o cmTC_3ac25 
gmake[2]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
gmake[1]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'



Detecting C compiler ABI info compiled with the following output:
Change Dir: /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_8e81c/fast && gmake[1]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_8e81c.dir/build.make CMakeFiles/cmTC_8e81c.dir/build
gmake[2]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o
/usr/bin/cc   -v -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o   -c /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c
Using built-in specs.
COLLECT_GCC=/usr/bin/cc
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/9/cc1 -quiet -v /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -version -o /tmp/ccTuVrPj.s
GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)
    compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/9/include
 /usr/local/include
 /usr/include
End of search list.
GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)
    compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0e6902e158034d8f60c5405e0210406c
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'
 as -v --64 -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o /tmp/ccTuVrPj.s
GNU assembler version 2.32 (x86_64-redhat-linux) using BFD version version 2.32-30.fc31
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64'
Linking C executable cmTC_8e81c
/home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8e81c.dir/link.txt --verbose=1
/usr/bin/cc     -v -rdynamic CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o  -o cmTC_8e81c 
Using built-in specs.
COLLECT_GCC=/usr/bin/cc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) 
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-rdynamic' '-o' 'cmTC_8e81c' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/9/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/9/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccTQ8sAE.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cmTC_8e81c /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/9 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../.. CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-redhat-linux/9/crtend.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o
COLLECT_GCC_OPTIONS='-v' '-rdynamic' '-o' 'cmTC_8e81c' '-mtune=generic' '-march=x86-64'
gmake[2]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'
gmake[1]: Leaving directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp'



Parsed C implicit include dir info from above output: rv=done
  found start of include info
  found start of implicit include info
    add: [/usr/lib/gcc/x86_64-redhat-linux/9/include]
    add: [/usr/local/include]
    add: [/usr/include]
  end of search list found
  collapse include dir [/usr/lib/gcc/x86_64-redhat-linux/9/include] ==> [/usr/lib/gcc/x86_64-redhat-linux/9/include]
  collapse include dir [/usr/local/include] ==> [/usr/local/include]
  collapse include dir [/usr/include] ==> [/usr/include]
  implicit include dirs: [/usr/lib/gcc/x86_64-redhat-linux/9/include;/usr/local/include;/usr/include]


Parsed C implicit link information from above output:
  link line regex: [^( *|.*[/\])(ld|CMAKE_LINK_STARTFILE-NOTFOUND|([^/\]+-)?ld|collect2)[^/\]*( |$)]
  ignore line: [Change Dir: /home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp]
  ignore line: []
  ignore line: [Run Build Command(s):/usr/bin/gmake cmTC_8e81c/fast && gmake[1]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp']
  ignore line: [/usr/bin/gmake -f CMakeFiles/cmTC_8e81c.dir/build.make CMakeFiles/cmTC_8e81c.dir/build]
  ignore line: [gmake[2]: Entering directory '/home/xxx.xxx/CLionProjects/assignment_2/cmake-build-debug/CMakeFiles/CMakeTmp']
  ignore line: [Building C object CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o]
  ignore line: [/usr/bin/cc   -v -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o   -c /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c]
  ignore line: [Using built-in specs.]
  ignore line: [COLLECT_GCC=/usr/bin/cc]
  ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none]
  ignore line: [OFFLOAD_TARGET_DEFAULT=1]
  ignore line: [Target: x86_64-redhat-linux]
  ignore line: [Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux]
  ignore line: [Thread model: posix]
  ignore line: [gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) ]
  ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64']
  ignore line: [ /usr/libexec/gcc/x86_64-redhat-linux/9/cc1 -quiet -v /home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/share/cmake-3.15/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -version -o /tmp/ccTuVrPj.s]
  ignore line: [GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)]
  ignore line: [    compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP]
  ignore line: []
  ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072]
  ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/include-fixed"]
  ignore line: [ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/9/../../../../x86_64-redhat-linux/include"]
  ignore line: [#include "..." search starts here:]
  ignore line: [#include <...> search starts here:]
  ignore line: [ /usr/lib/gcc/x86_64-redhat-linux/9/include]
  ignore line: [ /usr/local/include]
  ignore line: [ /usr/include]
  ignore line: [End of search list.]
  ignore line: [GNU C17 (GCC) version 9.2.1 20190827 (Red Hat 9.2.1-1) (x86_64-redhat-linux)]
  ignore line: [    compiled by GNU C version 9.2.1 20190827 (Red Hat 9.2.1-1), GMP version 6.1.2, MPFR version 3.1.6-p2, MPC version 1.1.0, isl version isl-0.16.1-GMP]
  ignore line: []
  ignore line: [GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072]
  ignore line: [Compiler executable checksum: 0e6902e158034d8f60c5405e0210406c]
  ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64']
  ignore line: [ as -v --64 -o CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o /tmp/ccTuVrPj.s]
  ignore line: [GNU assembler version 2.32 (x86_64-redhat-linux) using BFD version version 2.32-30.fc31]
  ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/]
  ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/]
  ignore line: [COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o' '-c' '-mtune=generic' '-march=x86-64']
  ignore line: [Linking C executable cmTC_8e81c]
  ignore line: [/home/xxx.xxx/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5662.56/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8e81c.dir/link.txt --verbose=1]
  ignore line: [/usr/bin/cc     -v -rdynamic CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o  -o cmTC_8e81c ]
  ignore line: [Using built-in specs.]
  ignore line: [COLLECT_GCC=/usr/bin/cc]
  ignore line: [COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper]
  ignore line: [OFFLOAD_TARGET_NAMES=nvptx-none]
  ignore line: [OFFLOAD_TARGET_DEFAULT=1]
  ignore line: [Target: x86_64-redhat-linux]
  ignore line: [Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux]
  ignore line: [Thread model: posix]
  ignore line: [gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC) ]
  ignore line: [COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/9/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/]
  ignore line: [LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/9/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/]
  ignore line: [COLLECT_GCC_OPTIONS='-v' '-rdynamic' '-o' 'cmTC_8e81c' '-mtune=generic' '-march=x86-64']
  link line: [ /usr/libexec/gcc/x86_64-redhat-linux/9/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/9/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccTQ8sAE.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cmTC_8e81c /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/9 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/9/../../.. CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-redhat-linux/9/crtend.o /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o]
    arg [/usr/libexec/gcc/x86_64-redhat-linux/9/collect2] ==> ignore
    arg [-plugin] ==> ignore
    arg [/usr/libexec/gcc/x86_64-redhat-linux/9/liblto_plugin.so] ==> ignore
    arg [-plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper] ==> ignore
    arg [-plugin-opt=-fresolution=/tmp/ccTQ8sAE.res] ==> ignore
    arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
    arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
    arg [-plugin-opt=-pass-through=-lc] ==> ignore
    arg [-plugin-opt=-pass-through=-lgcc] ==> ignore
    arg [-plugin-opt=-pass-through=-lgcc_s] ==> ignore
    arg [--build-id] ==> ignore
    arg [--no-add-needed] ==> ignore
    arg [--eh-frame-hdr] ==> ignore
    arg [--hash-style=gnu] ==> ignore
    arg [-m] ==> ignore
    arg [elf_x86_64] ==> ignore
    arg [-export-dynamic] ==> ignore
    arg [-dynamic-linker] ==> ignore
    arg [/lib64/ld-linux-x86-64.so.2] ==> ignore
    arg [-o] ==> ignore
    arg [cmTC_8e81c] ==> ignore
    arg [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o] ==> ignore
    arg [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o] ==> ignore
    arg [/usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o] ==> ignore
    arg [-L/usr/lib/gcc/x86_64-redhat-linux/9] ==> dir [/usr/lib/gcc/x86_64-redhat-linux/9]
    arg [-L/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64] ==> dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64]
    arg [-L/lib/../lib64] ==> dir [/lib/../lib64]
    arg [-L/usr/lib/../lib64] ==> dir [/usr/lib/../lib64]
    arg [-L/usr/lib/gcc/x86_64-redhat-linux/9/../../..] ==> dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../..]
    arg [CMakeFiles/cmTC_8e81c.dir/CMakeCCompilerABI.c.o] ==> ignore
    arg [-lgcc] ==> lib [gcc]
    arg [--push-state] ==> ignore
    arg [--as-needed] ==> ignore
    arg [-lgcc_s] ==> lib [gcc_s]
    arg [--pop-state] ==> ignore
    arg [-lc] ==> lib [c]
    arg [-lgcc] ==> lib [gcc]
    arg [--push-state] ==> ignore
    arg [--as-needed] ==> ignore
    arg [-lgcc_s] ==> lib [gcc_s]
    arg [--pop-state] ==> ignore
    arg [/usr/lib/gcc/x86_64-redhat-linux/9/crtend.o] ==> ignore
    arg [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o] ==> ignore
  collapse library dir [/usr/lib/gcc/x86_64-redhat-linux/9] ==> [/usr/lib/gcc/x86_64-redhat-linux/9]
  collapse library dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64] ==> [/usr/lib64]
  collapse library dir [/lib/../lib64] ==> [/lib64]
  collapse library dir [/usr/lib/../lib64] ==> [/usr/lib64]
  collapse library dir [/usr/lib/gcc/x86_64-redhat-linux/9/../../..] ==> [/usr/lib]
  implicit libs: [gcc;gcc_s;c;gcc;gcc_s]
  implicit dirs: [/usr/lib/gcc/x86_64-redhat-linux/9;/usr/lib64;/lib64;/usr/lib]
  implicit fwks: []

Ruaghain
  • 135
  • 1
  • 14
  • `${cblas}` is not `${blas}`. Did you try starting with simple `target_link_libraries(${PROJECT_NAME} PUBLIC /usr/local/lib/libblas.a)`? – KamilCuk Jan 14 '20 at 22:27
  • The symbol got linked when I tried. I am on Ubuntu by the way. Can you post the CMake log – Bpaul Jan 15 '20 at 09:23
  • @KamilCuk apologies, that was an update mistake. I tried your update anyway. No Joy I'm afraid. Same problem. – Ruaghain Jan 15 '20 at 10:33
  • @Bpaul I've amended the question to include the output. – Ruaghain Jan 15 '20 at 10:34
  • There is could be another library name like `libopenblas.a` to link with. – Andry Jan 15 '20 at 10:41
  • @Andry I could use openblas, however, I'm hoping to avoid that, and instead learn where I've gone wrong with my current implementation, and fix that ;-) – Ruaghain Jan 15 '20 at 13:15
  • Does the error message appear when you *run* the executable or when you compile ? If it’s when you run, then the library may have been linked as dynamic (not static) and the runtime linker can’t find the library – chmike Jan 15 '20 at 13:52
  • @chmike happens only when I run the application. I'll check that though. – Ruaghain Jan 15 '20 at 14:09

4 Answers4

0

Looks like the dynamic linker cannot find a shared library.

You can use ldd to inspect dynamic dependencies

Example looking at the dependencies of /bin/ls

ldd /bin/ls
             linux-vdso.so.1 (0x00007ffcc3563000)
             libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000)
             libcap.so.2 => /lib64/libcap.so.2 (0x00007f87e5254000)
             libc.so.6 => /lib64/libc.so.6 (0x00007f87e4e92000)
             libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f87e4c22000)
             libdl.so.2 => /lib64/libdl.so.2 (0x00007f87e4a1e000)
             /lib64/ld-linux-x86-64.so.2 (0x00005574bf12e000)
             libattr.so.1 => /lib64/libattr.so.1 (0x00007f87e4817000)
             libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f87e45fa000)

Ensure the .so files exist at the path specified.

ldd manpage

Mike Seeds
  • 400
  • 3
  • 10
  • Not likely, since the library is a static library (`libblas.a`). – scooter me fecit Jan 21 '20 at 20:21
  • It is a run-time error, has to be something to do with a shared library. libblas also has a .so version. – Mike Seeds Jan 23 '20 at 10:58
  • With respect, the OP used a static library, which resulted int a compile/link time error, going by the CMakeLists.txt content. On Linux, you would link with a `.so` to get the shared object/dynamic linking support, not the static `.a`. – scooter me fecit Jan 24 '20 at 19:10
  • @scootermefecit OP said it was a run-time error. "However when I try and run my application, I get the following linker error message:". – Mike Seeds Jan 25 '20 at 20:44
  • Were it truly a runtime error with a dynamic library (and I'm assuming the OP is on Linux), the app should have linked with a shared object library, ".so". But it didn't; it linked with a static library. Hence my skepticism that this is a dynamic library issue. – scooter me fecit Feb 06 '20 at 00:39
  • Someone asked him in the comments "Does the error message appear when you run the executable or when you compile ?" and he replied "happens only when I run the application". – Mike Seeds Feb 06 '20 at 12:13
0

I do not know how exactly you generated your libblas.a, but you could have a look at the FindBLAS CMake directive. (Take care about the note regarding C/C++)

https://cmake.org/cmake/help/v3.14/module/FindBLAS.html

lnksz
  • 421
  • 3
  • 15
  • I essentially did the following @Inksz 1. Extracted the BLAS compressed file to a directory 2. Ran `gfortran -O3 -c *.f` in that directory 3. Ran `ar cr libblas.a *.o` 4. Copied it to the lib directory: `sudo cp ./libblas.a /usr/local/lib/` – Ruaghain Jan 20 '20 at 18:28
0

There are a bunch of things that can go wrong here, but to simplify:

  1. copy libblas.a into the same directory as your program
  2. Reference it explicitly in the makefile.
  3. Check to see the location of CBLAS in your output (not shown)
  4. Verify the permissions of libblas.a, and look at the symbols using nm
  5. Force CMake to link everything statically (e.g. here static link question

Your symptoms suggest that you are picking up some other blas library at compile but not at runtime.

gbronner
  • 1,907
  • 24
  • 39
0

Your CMakeLists.txt should have something that looks like this, following the FindBLAS suggestion:

include(FindBLAS)

if (BLAS_FOUND)
    target_compile_options(${PROJECT_NAME} PRIVATE ${BLAS_LINKER_FLAGS})
    target_link_libraries(${PROJECT_NAME} ${BLAS_LIBRARIES})
endif ()
scooter me fecit
  • 1,053
  • 5
  • 15