andyvand / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Possible to build gmpy/gmpy2 against static GMP #85

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is it possible to build gmpy and/or gmpy2 against a static build of gmp (i.e., 
one that has been built with --disable-shared)? I am on OS X, and it doesn't 
work because of 

ImportError: 
dlopen(/Users/aaronmeurer/anaconda/envs/_test/lib/python3.3/site-packages/gmpy2.
so, 2): Library not loaded: libgmp.10.dylib
  Referenced from: /Users/aaronmeurer/anaconda/envs/_test/lib/python3.3/site-packages/gmpy2.so
  Reason: image not found

Original issue reported on code.google.com by asmeurer@gmail.com on 7 Feb 2014 at 11:11

GoogleCodeExporter commented 9 years ago
It's on my list to do for the next major release of gmpy2. I'll update the 
issue if I get it working.

Original comment by casevh on 8 Feb 2014 at 10:38

GoogleCodeExporter commented 9 years ago
I managed to build a statically linked version of gmpy 1.17. Here are the steps 
I followed:

1) Build gmp using

  ./configure --prefix=/opt/static --disable-shared --with-pic

2) Edit setup.py

   gmpy_ext = Extension('gmpy', sources=['src/gmpy.c'],
       include_dirs=incdirs,
       library_dirs=libdirs,
       extra_objects=["/opt/static/lib/libgmp.a"])

3) Build gmpy using:

   py26 setup.py build_ext -I/opt/static -L/opt/static -f install

There are probably better ways to do this, but this did work for me.

Original comment by casevh on 15 Mar 2014 at 6:11

GoogleCodeExporter commented 9 years ago
What does --with-pic do?

Original comment by asmeurer@gmail.com on 15 Mar 2014 at 7:38

GoogleCodeExporter commented 9 years ago
PIC stands for Position Independent Code. Roughly speaking, shared libraries 
can be loaded arbitrary locations in memory so they require code that can be 
relocated at runtime. After a static executable is linked, the code always runs 
at a fixed location in memory. When GMP compiles a static library, it assumes 
it will be linked to create a static executable so PIC is disabled.

Since we want to create a shared library by linking static libraries together, 
the static libraries must be compiled with PIC enabled.

My comments are based on GCC and Linux.

Original comment by casevh on 16 Mar 2014 at 5:39

GoogleCodeExporter commented 9 years ago
I'll be releasing version 2.0.4 that includes a --static option for setup.py to 
simplify building a statically linked library. I'll close this ticket for now.

Original comment by casevh on 28 May 2014 at 4:02