【问题标题】:undefined reference to cblas_sgemm未定义对 cblas_sgemm 的引用
【发布时间】:2016-09-03 03:13:13
【问题描述】:

我有以下make文件

g++ -Wall -O3 -g -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 Matrix.cc -L /usr/lib64/libcblas.so.0 util.cc word_io.cc net_lbl_2reps_scalable.cc train_lbl_2r_ptb.cc -o train_lbl_2r_ptb

但是我得到了错误

/tmp/cc9NLGFL.o:在函数Matrix::scaleAddAB(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:316: undefined reference tocblas_sgemm' /tmp/cc9NLGFL.o:在函数Matrix::scaleAddAtransB(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:330: undefined reference tocblas_sgemm' /tmp/cc9NLGFL.o:在函数Matrix::scaleAddABtrans(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:344: undefined reference tocblas_sgemm'

导致错误发生的函数:

void Matrix::scaleAddABtrans(const Matrix &A, const Matrix &B, float targetScale, float prodScale)
  {
  assert(A.rows() == rows() && A.cols() == B.cols() && B.rows() == cols());
  ::cblas_sgemm(CblasColMajor, CblasNoTrans, CblasTrans,
                A.rows(), B.rows(), A.cols(),
                prodScale, // Scale the product by 1
                A.data(), A.rows(),
                B.data(), B.rows(),
                targetScale, // Scale the target by this before adding the product matrix
                data(), rows());
}

它可以链接文件但找不到sgemm。无法理解为什么?

【问题讨论】:

  • -L /usr/lib64/libcblas.so.0 在我看来不合适。不应该是-L/usr/lib64 -lcblas

标签: c++ matrix linker-errors cblas


【解决方案1】:

正如 user6292850 所说,-L 选项采用目录名称,而不是库名称。要命名库,请使用-lcblas。在这种情况下,您可能不需要使用-L,因为/usr/lib64 可能在默认搜索路径上。

另外一点建议:将链接器选项和库名称​​放在任何源文件名和目标文件名之后。在 ma​​ke 中,它通常看起来像这样:

$ c++ $(CXXFLAGS) -o train_lbl_2r_ptb $(SRC) $(LDFLAGS) -lcblas

您这样做是因为链接器会沿着线路向下工作,以解析名称。如果在您的示例中,util.cc 使用 cblas 函数,则链接器可能找不到它,除非该库出现在命令行的右侧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 2022-01-22
    • 2016-04-04
    • 2015-11-03
    • 2011-08-11
    • 2019-07-22
    • 2015-07-20
    相关资源
    最近更新 更多