简体   繁体   English

编译 OpenBLAS C++ 项目给出错误“体系结构 x86_64 的未定义符号”

[英]Compiling OpenBLAS C++ project gives error "Undefined symbols for architecture x86_64"

I have been trying to get OpenBLAS (and other BLAS libraries) to work for a very long time now, though I am unable to get the project to compile correctly, it always gives the the same type of error no matter what BLAS library I use.我一直试图让 OpenBLAS(和其他 BLAS 库)工作很长时间,虽然我无法让项目正确编译,但无论我使用什么 BLAS 库,它总是会给出相同类型的错误.

The code I am trying to run is very simple, it is some example code from the OpenBLAS git repository.我试图运行的代码非常简单,它是来自 OpenBLAS git 存储库的一些示例代码。

#include "cblas.h"
#include <cstdio>

int main()
{
    int i=0;
    double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
    double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
    double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5};
    cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,3,3,2,1,A, 3, B, 3,2,C,3);

    for(i=0; i<9; i++)
        printf("%lf ", C[i]);
    printf("\n");

    return 0;
}

In the CMakeLists.txt file I have added the following line in order to attempt to link the OpenBLAS library to my code:CMakeLists.txt文件中,我添加了以下行以尝试将 OpenBLAS 库链接到我的代码:

include_directories(/Path/To/OpenBlas-0.3.7)

When I try to run the code, however, the resulting error is given:但是,当我尝试运行代码时,给出了结果错误:

When using OpenBLAS :使用 OpenBLAS 时

Scanning dependencies of target OpenBlasTesting
[ 50%] Building CXX object CMakeFiles/OpenBlasTesting.dir/main.cpp.o
[100%] Linking CXX executable OpenBlasTesting
Undefined symbols for architecture x86_64:
  "_cblas_dgemm", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [CMakeFiles/OpenBlasTesting.dir/build.make:84: OpenBlasTesting] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/OpenBlasTesting.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/OpenBlasTesting.dir/rule] Error 2
gmake: *** [Makefile:118: OpenBlasTesting] Error 2

When using the Intel MKL, the dgemm_example.c file, and a slightly altered line in the CMakeLists.txt file:使用英特尔 MKL 时,dgemm_example.c 文件和CMakeLists.txt文件中稍微改变的行:

Scanning dependencies of target MKLTesting
[ 50%] Building C object CMakeFiles/MKLTesting.dir/main.c.o
[100%] Linking C executable MKLTesting
Undefined symbols for architecture x86_64:
  "_MKL_free", referenced from:
      _main in main.c.o
  "_MKL_malloc", referenced from:
      _main in main.c.o
  "_cblas_dgemm", referenced from:
      _main in main.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [CMakeFiles/MKLTesting.dir/build.make:84: MKLTesting] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/MKLTesting.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/MKLTesting.dir/rule] Error 2
gmake: *** [Makefile:118: MKLTesting] Error 2

I have supplied both in case there is some detail that is not provided by one of the error codes.我已经提供了两者,以防有错误代码之一未提供的一些细节。

I am using CLion on MacOS Catalina and am programming in C++.我在 MacOS Catalina 上使用 CLion 并且正在用 C++ 编程。

Any help as to how to resolve this issue would be greatly appreciated.任何有关如何解决此问题的帮助将不胜感激。

Thank you for everyone's help!谢谢大家的帮助!

I see no problems with your case.我看你的情况没有问题。 I only added #include "mkl_cblas.h" instead of "clbas.h".我只添加了 #include "mkl_cblas.h" 而不是 "c​​lbas.h"。 and then linking with Intel mkl from command line like recommended by MKL Linker Adviser : -L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl and then launching the executable, I see: ./a.out 11.000000 -9.000000 5.000000 -9.000000 21.000000 -1.000000 5.000000 -1.000000 3.000000然后像MKL Linker Adviser推荐的那样从命令行与 Intel mkl 链接: -L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl 然后启动可执行文件,我看到: ./a.out 11.000000 -9.000000 5.000000 -9.000000 21.000000 -1.000000 5.000000 -1.000000 3.000000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM