tca19 / near-lossless-binarization

This repository contains source code to binarize any real-value word embeddings into binary vectors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined reference to `cblas_sgemm' error when make

kaierlong opened this issue · comments

OS : ubuntu 16.04.6
gcc version : 5.4.0-6ubuntu1~16.04.11

First, I installed the OpenBLAS.

sudo apt install libopenblas-dev
sudo update-alternatives --config libblas.so.3

Then, I run make and show the following error.

gcc -ansi -pedantic -lm -pthread -Ofast -funroll-loops -lblas -Wall -Wextra -Wno-unused-result binarize.c -o binarize
/tmp/cc9DvK9o.o: In function `apply_regularizarion_gradient':
binarize.c:(.text+0xea8): undefined reference to `cblas_sgemm'
binarize.c:(.text+0x1087): undefined reference to `cblas_sgemm'
/tmp/cc9DvK9o.o: In function `apply_reconstruction_gradient':
binarize.c:(.text+0x1117): undefined reference to `cblas_sgemm'
binarize.c:(.text+0x149b): undefined reference to `cblas_sgemm'
binarize.c:(.text+0x1c54): undefined reference to `cblas_sgemm'
/tmp/cc9DvK9o.o:binarize.c:(.text+0x22b7): more undefined references to `cblas_sgemm' follow
collect2: error: ld returned 1 exit status
makefile:28: recipe for target 'binarize' failed
make: *** [binarize] Error 1

How can I deal with this problem, any help?

If I change the order of line 28, it will be ok.

$(CC) $(CFLAGS) binarize.c -o binarize
to
$(CC) binarize.c -o binarize $(CFLAGS)

But i don't know why.

commented

The software has been tested on Debian with GCC 8.2 and GCC 8.3 and this error was not present. I tested it on Ubuntu 16.04 with GCC 5.4 and was able to replicate the same error as you.

The reason is that the order matters when linking libraries for compilation (in our case OpenBLAS). Libraries must be placed after the source file, so -lblas should come after binarize.c in Makefile.

The solution you propose works because -lblas is in $(CFLAGS) so moving the flags at the end of the line has the effect of moving -lblas after the source file.