How do I statically link zstd library to my dynamic library?

user2577547

I am trying to statically link zstd library(I have libzstd.a or libzstd.so) to my shared library libtest.so. The idea is that when deploying libtest.so in our application, we don't have to depend on libzstd.a or libzstd.so any more, so we have to statically link the zstd library.

I tried these:

cc  -fPIC -Wl,-soname=libtest.so -static-libgcc  -shared -o libtest.so myobjects.o -ldl -lc -L/path/to/libzstd -l:libzstd.a
cc  -fPIC -Wl,-soname=libtest.so -static-libgcc  -shared -o libtest.so myobjects.o -ldl -lc -Wl,-Bstatic -L/path/to/libzstd -l:libzstd.a
cc  -fPIC -Wl,-soname=libtest.so -static-libgcc  -shared -o libtest.so myobjects.o -ldl -lc /path/to/libzstd/libzstd.a

But they're all giving me this error:

/bin/ld: /path/to/libzstd/libzstd.a(zstd_common.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; 
recompile with -fPIC
/path/to/libzstd/libzstd.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [libtest.so] Error 1

What are the problem here? Thank you!

Mike Kinghan

All object files that are linked into a shared library must be compiled as Position Independent Code (compiler option -fPIC).

The linker error:

/bin/ld: /path/to/libzstd/libzstd.a(zstd_common.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; 
recompile with -fPIC

is telling you that the linkage of the shared library libtest.so needs the object file zstd_common.o from the archive libzstd.a, but that object file was not compiled with -fPIC.

So you must rebuild libzstd.a from source, this time compiling the object files that it contains with -fPIC.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I statically link a Haskell library with a Rust project?

How do I include shared-library dependencies with my binary (w/o using a .deb or .rpm), and/or statically link against PulseAudio?

How do I statically link the openssl-sys crate into a shared library?

How do you statically link a c library in go using cgo?

How can I link dynamic library depending on another dynamic library?

Cmake: How to statically link packages to shared library?

How do I link a library using CMake?

How do I link cabal library and executable?

how do i link wininet library with cmake

How do you tell CMake to statically link to a library in a package found with find_package?

How do I stop the error "The ordinal 3252 could not be located in the dynamic link library mongod.exe"?

Can I force a dynamic library to link to a specific dynamic library dependency?

How to use pkg-config to link a library statically

How do I statically link FFTW on windows?

How can I link my C program against the Arb library?

How do I tell cmake I want my project to link libraries statically?

Telling gcc directly to link a library statically

Statically link google protobuf lib into a dll library

How do I link a native library to a Java project in VSCode?

How do I tell CMake to link in a static library in the source directory?

How do I link against libtool static la library?

How do i set link in QrCode library php

How do I link the library correctly using cmake?

Dynamic link library in C

How to force executable to link dynamic library

How to use dynamic link library with CMake?

How do I unit-test a dynamic library using gcov?

How do I use a shared dynamic library in c++ project?

How do I share my Windows Music Library with my Linux Library?

TOP Ranking

HotTag

Archive