I have the following make file
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
However I get the error
/tmp/cc9NLGFL.o: In function
Matrix::scaleAddAB(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:316: undefined reference to
cblas_sgemm' /tmp/cc9NLGFL.o: In functionMatrix::scaleAddAtransB(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:330: undefined reference to
cblas_sgemm' /tmp/cc9NLGFL.o: In functionMatrix::scaleAddABtrans(Matrix const&, Matrix const&, float, float)': /home/ncelm/Matrix.cc:344: undefined reference to
cblas_sgemm'
The function due to which the error is occuring:
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());
}
It is able to link the file but not find the sgemm
. Unable to understand why?
As user6292850 notes, the
-L
option takes a directory name, not a library name. To name the library, use-lcblas
. You probably don't need to use-L
in this case, because/usr/lib64
is likely on the default search path.One other bit of advice: Put the linker options and the library names after any source and object filenames on the command line. In make it would conventionally look something like this:
You do that because the linker works its way down the line, as it were, to resolve names. If, in your example,
util.cc
uses a cblas function, the linker might not find it unless the library appears to the right on the command line.