How to link mnist_caffe.cpp statically with libarmnn.a and libarmnnCaffeParser.a
Mo-Abdelgawad opened this issue · comments
I have built static versions of armnn and armnnCaffeParser libraries; libarmnn.a
and libarmnnCaffeParser.a
respectively.
I am trying to compile and link mnist_caffe.cpp statically with them but getting numerous undefined references
errors.
To do static linking: I edited the command in the mnist_caffe
target in the armnn-mnist
Makefile as follows:
--mnist_caffe
target before editting:
mnist_caffe: mnist_caffe.cpp mnist_loader.hpp
g++ -O3 -std=c++14 -I$(ARMNN_INC) mnist_caffe.cpp -o mnist_caffe -L$(ARMNN_LIB) -larmnn -larmnnCaffeParser
--mnist_caffe
target after editing (just added -static
flag and used aarch64-linux-gnu-g++
instead of g++
since I am cross-compiling on an x86 machine)
mnist_caffe: mnist_caffe.cpp mnist_loader.hpp
aarch64-linux-gnu-g++ -O3 -std=c++14 -I$(ARMNN_INC) mnist_caffe.cpp -o mnist_caffe -L$(ARMNN_LIB) -static -larmnn -larmnnCaffeParser
Note that ARMNN_LIB
has only static versions of armnn and armnnCaffeParser libraries (i.e. it only has armnn.a
and armnnCaffeParser.a
, there are no .so
versions of them)
I am only interested in the mnist_caffe target. So I run $ make mnist_caffe
. The result is numerous undefined reference errors that I directed all to static.txt attached below:
static.txt
My question in a nutshell: How to output a working statically-linked mnist_caffe
executable given that I have both libarmnn.a
and libarmnnCaffeParser.a
?
PS: I am only interested in compiling and linking. In other words, I am only interested in the output executable mnist_caffe, but I want it to be statically linked since I will take it and run it on an ARM simulator that only accepts statically-linked executables.
Solved it!
I followed the undefined references errors and found out that I also have to provide -lprotobuf -larmnnUtils -lboost_filesystem -lboost_system -lpthread -ldl -lc
among the static libraries list! Although they were already linked in the -larmnnCaffeParser -larmnn
libraries!
Anyhow, it works now. The final g++ command is as below. Please keep the order of the static libraries as it is. Linker will complain if you change the order. To help the linker find those libraries, you even provide their directories by -L
option or you find them yourself and make a copy in $(ARMNN_LIB)
like I did. Note that all the libraries listed are for aarch64. In otherwords, you have to cross-compile -lprotobuf -larmnnUtils -lboost_filesystem -lboost_system
, and you willl find -lpthread -ldl -lc
already there in the aarch64-linux-gnu
compiler directory.
mnist_caffe_static: mnist_caffe.cpp mnist_loader.hpp
aarch64-linux-gnu-g++ -static -no-pie -O3 -std=c++14 -I$(ARMNN_INC) mnist_caffe.cpp -o mnist_caffe_static -L$(ARMNN_LIB) -larmnnCaffeParser -larmnn -lprotobuf -larmnnUtils -lboost_filesystem -lboost_system -lpthread -ldl -lc