首页 > 解决方案 > 在 macOS Catalina 上编译 Intel 的 MKL CBLAS 示例文件时出现问题

问题描述

我想解决 C++ 中的一个问题,该问题涉及找到方程组的解决方案。我看到英特尔的 MKL 包为此提供了必要的工具。我已经下载了整个库并安装了它。
首先,我想看看是否一切正常,所以我首先尝试编译一个由 intel 提供的简单示例(请参阅此处的 C 源文件)。这是一个借助cblas_dgem函数将两个矩阵相乘的程序。但是,我收到很多警告和错误:

basavyr@Roberts-MacBook-Pro Desktop % g++ mkl-lab-solution.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
In file included from mkl-lab-solution.c:30:
In file included from /usr/local/include/stdio.h:64:
/usr/local/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        unsigned char   *_base;
                        ^
/usr/local/include/_stdio.h:93:16: note: insert '_Nullable' if the pointer may be null
        unsigned char   *_base;
                        ^
                          _Nullable 
/usr/local/include/_stdio.h:93:16: note: insert '_Nonnull' if the pointer should never be null
        unsigned char   *_base;
                        ^
                          _Nonnull 
/usr/local/include/_stdio.h:138:32: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        int     (* _Nullable _read) (void *, char *, int);
                                          ^
/usr/local/include/_stdio.h:138:32: note: insert '_Nullable' if the pointer may be null
        int     (* _Nullable _read) (void *, char *, int);
                                          ^
                                           _Nullable
/usr/local/include/_stdio.h:138:32: note: insert '_Nonnull' if the pointer should never be null
        int     (* _Nullable _read) (void *, char *, int);
                                          ^
                                           _Nonnull
/usr/local/include/_stdio.h:138:40: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        int     (* _Nullable _read) (void *, char *, int);
                                                  ^
/usr/local/include/_stdio.h:138:40: note: insert '_Nullable' if the pointer may be null
        int     (* _Nullable _read) (void *, char *, int);
                                                  ^
                                                   _Nullable
/usr/local/include/_stdio.h:138:40: note: insert '_Nonnull' if the pointer should never be null
        int     (* _Nullable _read) (void *, char *, int);
                                                  ^
                                                   _Nonnull
/usr/local/include/_stdio.h:139:35: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        fpos_t  (* _Nullable _seek) (void *, fpos_t, int);
                                          ^
/usr/local/include/_stdio.h:139:35: note: insert '_Nullable' if the pointer may be null
        fpos_t  (* _Nullable _seek) (void *, fpos_t, int);
                                          ^
                                           _Nullable
/usr/local/include/_stdio.h:139:35: note: insert '_Nonnull' if the pointer should never be null
        fpos_t  (* _Nullable _seek) (void *, fpos_t, int);
                                          ^
                                           _Nonnull
/usr/local/include/_stdio.h:140:32: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        int     (* _Nullable _write)(void *, const char *, int);
                                          ^
/usr/local/include/_stdio.h:140:32: note: insert '_Nullable' if the pointer may be null
        int     (* _Nullable _write)(void *, const char *, int);
                                          ^
                                           _Nullable
/usr/local/include/_stdio.h:140:32: note: insert '_Nonnull' if the pointer should never be null
        int     (* _Nullable _write)(void *, const char *, int);
                                          ^
                                           _Nonnull
/usr/local/include/_stdio.h:140:46: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        int     (* _Nullable _write)(void *, const char *, int);
                                                        ^
/usr/local/include/_stdio.h:140:46: note: insert '_Nullable' if the pointer may be null
        int     (* _Nullable _write)(void *, const char *, int);
                                                        ^
                                                         _Nullable
/usr/local/include/_stdio.h:140:46: note: insert '_Nonnull' if the pointer should never be null
        int     (* _Nullable _write)(void *, const char *, int);
                                                        ^
                                                         _Nonnull
/usr/local/include/_stdio.h:144:18: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        struct __sFILEX *_extra; /* additions to FILE to not break ABI */
                        ^
/usr/local/include/_stdio.h:144:18: note: insert '_Nullable' if the pointer may be null
        struct __sFILEX *_extra; /* additions to FILE to not break ABI */
                        ^
                          _Nullable 
/usr/local/include/_stdio.h:144:18: note: insert '_Nonnull' if the pointer should never be null
        struct __sFILEX *_extra; /* additions to FILE to not break ABI */
                        ^
                          _Nonnull 
In file included from mkl-lab-solution.c:30:
/usr/local/include/stdio.h:67:13: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
extern FILE *__stdinp;
            ^
/usr/local/include/stdio.h:67:13: note: insert '_Nullable' if the pointer may be null
extern FILE *__stdinp;
            ^
              _Nullable 
/usr/local/include/stdio.h:67:13: note: insert '_Nonnull' if the pointer should never be null
extern FILE *__stdinp;
            ^
              _Nonnull 
/usr/local/include/stdio.h:386:41: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
                 int (* _Nullable)(void *, const char *, int),
                                        ^
/usr/local/include/stdio.h:386:41: note: insert '_Nullable' if the pointer may be null
                 int (* _Nullable)(void *, const char *, int),
                                        ^
                                         _Nullable
/usr/local/include/stdio.h:386:41: note: insert '_Nonnull' if the pointer should never be null
                 int (* _Nullable)(void *, const char *, int),
                                        ^
                                         _Nonnull
/usr/local/include/stdio.h:386:55: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
                 int (* _Nullable)(void *, const char *, int),
                                                      ^
/usr/local/include/stdio.h:386:55: note: insert '_Nullable' if the pointer may be null
                 int (* _Nullable)(void *, const char *, int),
                                                      ^
                                                       _Nullable
/usr/local/include/stdio.h:386:55: note: insert '_Nonnull' if the pointer should never be null
                 int (* _Nullable)(void *, const char *, int),
                                                      ^
                                                       _Nonnull
/usr/local/include/stdio.h:387:44: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
                 fpos_t (* _Nullable)(void *, fpos_t, int),
                                           ^
/usr/local/include/stdio.h:387:44: note: insert '_Nullable' if the pointer may be null
                 fpos_t (* _Nullable)(void *, fpos_t, int),
                                           ^
                                            _Nullable
/usr/local/include/stdio.h:387:44: note: insert '_Nonnull' if the pointer should never be null
                 fpos_t (* _Nullable)(void *, fpos_t, int),
                                           ^
                                            _Nonnull
/usr/local/include/stdio.h:388:41: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
                 int (* _Nullable)(void *));
                                        ^
/usr/local/include/stdio.h:388:41: note: insert '_Nullable' if the pointer may be null
                 int (* _Nullable)(void *));
                                        ^
                                         _Nullable
/usr/local/include/stdio.h:388:41: note: insert '_Nonnull' if the pointer should never be null
                 int (* _Nullable)(void *));
                                        ^
                                         _Nonnull
/usr/local/include/stdio.h:384:6: warning: pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
FILE    *funopen(const void *,
        ^
/usr/local/include/stdio.h:384:6: note: insert '_Nullable' if the pointer may be null
FILE    *funopen(const void *,
        ^
          _Nullable 
/usr/local/include/stdio.h:384:6: note: insert '_Nonnull' if the pointer should never be null
FILE    *funopen(const void *,
        ^
          _Nonnull 
mkl-lab-solution.c:85:15: warning: conversion from string literal to 'char *' is deprecated
      [-Wc++11-compat-deprecated-writable-strings]
                print_arr(N,"a", a);
                            ^
mkl-lab-solution.c:86:15: warning: conversion from string literal to 'char *' is deprecated
      [-Wc++11-compat-deprecated-writable-strings]
                print_arr(N,"b", b);
                            ^
mkl-lab-solution.c:87:15: warning: conversion from string literal to 'char *' is deprecated
      [-Wc++11-compat-deprecated-writable-strings]
                print_arr(N,"c", c);
                            ^
16 warnings generated.
Undefined symbols for architecture x86_64:
  "_cblas_dgemm", referenced from:
      Dgemm_multiply(double*, double*, double*, int) in mkl-lab-solution-96315a.o
ld: symbol(s) not found for architecture x86_64
**clang: error:** linker command failed with exit code 1 (use -v to see invocation)
basavyr@Roberts-MacBook-Pro Desktop % 

使用以下命令完成编译:g++ -m64 -I${MKLROOT}/include mkl-lab-solution.c

我正在运行 macOS Catalina (10.15.3)。我的 C++ 编译器没有问题(到目前为止我运行的所有内容都没有问题)

任何想法为什么会发生这种情况,我该如何解决这个问题?

标签: c++cmacosintel-mkl

解决方案


您需要链接 mkl 的库。请参阅 mkl 链接器顾问以查看您需要链接的 mkl 库列表。这是该顾问的列表:https ://software.intel.com/en-us/articles/intel-mkl-link-line-advisor 。


推荐阅读