Compiling a static version of GMP for `-Wl,--whole-archive`
Cade Brown
brown.cade at gmail.com
Fri Jul 3 06:50:46 UTC 2020
For anyone who has had this problem,
My solution was including `-Wl,-Bsymbolic` before linking entire libraries,
i.e.:
```
gcc -shared -O3 -std=c99 $(MY_OBJ) \
-Wl,-Bsymbolic \
-Wl,--whole-archive deps/prefix/lib/libgmp.a -Wl,--no-whole-archive \
-o libmylibrary.so
```
Thanks,
~
Cade Brown
Working on MAGMA <https://icl.cs.utk.edu/magma/>
http://cade.site
http://chemicaldevelopment.us
On Thu, Jul 2, 2020 at 5:41 AM Marc Glisse <marc.glisse at inria.fr> wrote:
> On Wed, 1 Jul 2020, Cade Brown wrote:
>
> > Hello all,
> >
> > I am trying to compile a static version of GMP (i.e. libgmp.a) on Linux
> > (Ubuntu) which I can embed fully in a .so I am compiling. I should be
> able
> > to do this as long as GMP contains PIC.
> >
> > If I configure with `$ ./configure --enable-static --disable-shared
> > --with-pic --prefix=deps/prefix`
> >
> > (and then make && make install)
> >
> > I later compile my library with:
> >
> > ```
> > $ gcc -shared -O3 -std=c99 $(MY_OBJ) \
> > -Wl,--whole-archive deps/prefix/lib/libgmp.a -Wl,--no-whole-archive \
> > -o libmylibrary.so
> > ```
> >
> > Obviously, some steps are simplified for brevity, but I get the error:
> >
> > ```
> > usr/bin/ld: deps/prefix/lib/libgmp.a(dive_1.o): relocation R_X86_64_PC32
> > against symbol `__gmp_binvert_limb_table' can not be used when making a
> > shared object; recompile with -fPIC
> > /usr/bin/ld: final link failed: bad value
> > ```
> >
> > Any help, or experiences others have had embedding GMP into a shared
> > library?
>
> What you described seems to work for me, using the current sources from
> master. Is m4 correctly called with -DPIC on dive_1.asm in your build?
>
> --
> Marc Glisse
>
More information about the gmp-discuss
mailing list