ueno/ruby-gpgme

gpgme_n.c fails to compile without -fPIC on x86_64

Closed this issue · 4 comments

Installation of the gem fails on a 64bit system:

$ gem install --install-dir ./tmp gpgme
Building native extensions.  This could take a while...
ERROR:  Error installing gpgme:
        ERROR: Failed to build gem native extension.

...
make
compiling gpgme_n.c
linking shared-object gpgme_n.so
/usr/bin/ld: /usr/lib/libgpgme.a(data.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/libgpgme.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [gpgme_n.so] Error 1
$ uname -a
Linux example.com 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3+deb7u2 x86_64 GNU/Linux

It compiles fine on 32 bit. When building the extensions, gpgme-config --cflags is run to determine what flags to add to CFLAGS before compiling. The output of this command is empty, though, so it won't add -fPIC to the list of CFLAGS.

I'm using GCC version 4.7.2 (Debian 4.7.2-5).

ueno commented

Could you paste the complete build log? It looks strange to me that gpgme_n.so is being linked with /usr/lib/libgpgme.a, while Debian places x86_64 libs under /usr/lib/x86_64-linux-gnu.

This is the complete output I get:

libertree@at:~/libertree/packaging$ gem install --install-dir ./tmp gpgme
Building native extensions.  This could take a while...
ERROR:  Error installing gpgme:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
************************************************************************
IMPORTANT!  gpgme gem uses locally built versions of required C libraries,
namely libgpg-error, libassuan, and gpgme.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall gpgme gem as
follows:

    gem install gpgme -- --use-system-libraries

************************************************************************
Extracting libgpg-error-1.13.tar.bz2 into tmp/x86_64-linux-gnu/ports/libgpg-error/1.13... OK
Running 'configure' for libgpg-error 1.13... OK
Running 'compile' for libgpg-error 1.13... OK
Running 'install' for libgpg-error 1.13... OK
Activating libgpg-error 1.13 (from /home/libertree/libertree/packaging/tmp/gems/gpgme-2.0.6/ports/x86_64-linux-gnu/libgpg-error/1.13)...
Extracting libassuan-2.1.1.tar.bz2 into tmp/x86_64-linux-gnu/ports/libassuan/2.1.1... OK
Running 'configure' for libassuan 2.1.1... OK
Running 'compile' for libassuan 2.1.1... OK
Running 'install' for libassuan 2.1.1... OK
Activating libassuan 2.1.1 (from /home/libertree/libertree/packaging/tmp/gems/gpgme-2.0.6/ports/x86_64-linux-gnu/libassuan/2.1.1)...
Extracting gpgme-1.5.0.tar.bz2 into tmp/x86_64-linux-gnu/ports/gpgme/1.5.0... OK
Running 'configure' for gpgme 1.5.0... OK
Running 'compile' for gpgme 1.5.0... OK
Running 'install' for gpgme 1.5.0... OK
Activating gpgme 1.5.0 (from /home/libertree/libertree/packaging/tmp/gems/gpgme-2.0.6/ports/x86_64-linux-gnu/gpgme/1.5.0)...
checking for linker flags for static linking... -Wl,-Bstatic
checking for gpgme.h... yes
checking for gpgme >= 1.1.3... yes
checking for gpgme_op_export_keys()... yes
creating Makefile

make
compiling gpgme_n.c
linking shared-object gpgme_n.so
/usr/bin/ld: /usr/lib/libgpgme.a(data.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/libgpgme.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [gpgme_n.so] Error 1


Gem files will remain installed in /home/libertree/libertree/packaging/tmp/gems/gpgme-2.0.6 for inspection.
Results logged to /home/libertree/libertree/packaging/tmp/gems/gpgme-2.0.6/ext/gpgme/gem_make.out
ueno commented

Thanks, confirmed the issue. 325e772 should fix this.

Thanks. This fixed it.