I am compiling a C++
program with -static
so that I can take my program to a server and run it. The server has not all libraries installed I am linking with and when trying to run the program I get the error that libopenblas.so.0
can not be found as OpenBLAS
is not installed:
error while loading shared libraries: libopenblas.so.0: cannot open shared object file: No such file or directory
I need OpenBLAS
for the linear algebra library Armadillo
and I compile with the flags
-std=c++11 -static -pthread -Ofast -march=native -mtune=native -m64 -Wall -Werror -Wextra -Wno-long-long -Ishared_methods -Icreate_codes/source_files -Ievaluate_codes/source_files -Igenomes/source_files -lopenblas -llapack -lgfortran
So is it not possible to statically link OpenBLAS
or did I do something wrong?
EDIT: This is my makefile. I have removed the commands and definitions for other programs for simplicity.
CXX = h5c++
CXXFLAGS= -std=c++11 -static -pthread -Ofast -march=native -mtune=native -m64 -Wall -Werror -Wextra -Wno-long-long -Ishared_methods -Ievaluate_codes/source_files
ENDFLAGS = -lopenblas -llapack -lgfortran
RELDIR_E = ./evaluate_codes/source_files
RELDIR_M = ./shared_methods
HEADERS = $(RELDIR_M)/methods.h
SRCS_E_MIR = $(RELDIR_E)/mir.cpp \
$(RELDIR_M)/methods.cpp
OBJS_E_MIR = $(SRCS_E_MIR:.cpp=.o)
TARGET_E_MIR = evaluate_codes/mir.out
e_mir: $(OBJS_E_MIR)
$(CXX) $(LDFLAGS) $(OBJS_E_MIR) $(LIBS) -o $(TARGET_E_MIR) $(ENDFLAGS)
clean_e_mir:
rm -f $(OBJS_E_MIR) $(TARGET_E_MIR)
EDIT 2: On my machine all the static (.a
) and shared (.so
) libraries exist and the program runs, but on the server I do not have all of the libraries. That is why I want to build it fully static, but it seems like the dependencies of the libraries are not fully included as shown by ldd mir.out
:
linux-vdso.so.1 => (0x00007fff74532000)
libopenblas.so.0 => /usr/lib/libopenblas.so.0 (0x00007fe73dbc8000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe73d9ab000)
libsz.so.2 => /usr/lib/x86_64-linux-gnu/libsz.so.2 (0x00007fe73d7a8000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe73d58e000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe73d38a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe73d008000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe73ccff000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe73cae9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe73c71f000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007fe73c3f4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe73fc5c000)
libaec.so.0 => /usr/lib/x86_64-linux-gnu/libaec.so.0 (0x00007fe73c1ec000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007fe73bfad000)
So how can I tell the compiler to include those dependencies in a static way?