"undefined reference to 'cblas_ddot'" when using cblas library

I don't know where it is going wrong. Why does the compiler said the "cblas_ddot" is undefined reference?

1 1 1 silver badge asked Oct 22, 2013 at 2:05 1,576 2 2 gold badges 15 15 silver badges 31 31 bronze badges What does your GCC command line, or Makefile look like? Commented Oct 22, 2013 at 2:10

2 Answers 2

You can't just include the header - that only tells the compiler that the functions exist somewhere. You need to tell the linker to link against the cblas library.

Assuming you have a libcblas.a file, you can tell GCC about it with -lcblas .

The web site for GNU Scientific Library tells you how to do this:

answered Oct 22, 2013 at 2:07 Jonathon Reinhart Jonathon Reinhart 136k 37 37 gold badges 262 262 silver badges 337 337 bronze badges

I tried gcc -Wall -I/usr/include -c test.c and it works. But then I executed gcc test.o -o test , it still was undefined reference to 'cblas_ddot' .

Commented Oct 22, 2013 at 2:19

The first invokation of gcc is just compiling test.c to test.o . The library is not used at all yet. If you run readelf -s test.o , you will see the unresolved symbol cblas_ddot . Your second invokation of gcc is just linking test.o against libc and creating the final output executable. It is here that you need to specify linking against the cblas library.