对cblas_sgemm的未定义引用
undefined reference to cblas_sgemm
我有以下制作文件
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 to
cblas_sgemm'中/tmp/cc9NLGFL.o:在函数Matrix::scaleAddAtransB(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:330: undefined reference to
cblas_sgemm'中/tmp/cc9NLGFL.o:在函数Matrix::scaleAddABtrans(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:344: undefined reference to
cblas_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
。无法理解为什么?
正如user6292850所指出的,-L
选项采用目录名,而不是库名。要命名库,请使用-lcblas
。在这种情况下,您可能不需要使用-L
,因为/usr/lib64
可能在默认搜索路径上。
还有一点建议:在命令行上,将链接器选项和库名称放在任何源和对象文件名之后。在make中,它通常看起来像这样:
$ c++ $(CXXFLAGS) -o train_lbl_2r_ptb $(SRC) $(LDFLAGS) -lcblas
这样做是因为链接器按照原来的方式解析名称。在您的示例中,如果util.cc
使用cblas函数,则链接器可能找不到它,除非该库显示在命令行的右侧。
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用