C extension: R_X86_64_32 problem when inlcuding a xxxxx.a library(64 bits SO)

Discussion in 'Ruby' started by Iñaki Baz Castillo, Feb 5, 2011.

  1. Hi, I must include a header (udns.h) and library (libudns.a) in a Ruby
    C extension (Linux 64 bits).

    In extconf.rb I set:

    have_library("udns")

    "ruby extconf" creates the Makefile:
    --------------------------------
    checking for main() in -ludns... yes
    creating Makefile
    --------------------------------

    but "make" command fails:
    -------------------------------
    gcc -I. -I/usr/include/ruby-1.9.1/x86_64-linux
    -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I.
    -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -o em_udns.o -c em_udns.c
    gcc -shared -o em_udns.so em_udns.o -L. -L/usr/lib -L. -rdynamic
    -Wl,-export-dynamic -lruby-1.9.1 -ludns -lpthread -lrt -ldl -lcrypt
    -lm -lc
    /usr/bin/ld: ./libudns.a(udns_resolver.o): relocation R_X86_64_32
    against `dns_defctx' can not be used when making a shared object;
    recompile with -fPIC
    /libudns.a: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    -------------------------------

    I know that "relocation R_X86_64_32" issue occurs with some libraries
    in 64 bits and -fPIC is required. However AFAIK the above gcc command
    does include -fPIC, am I right?

    Anyhow, I can compile a pure C file (no Ruby) in a folder with these files:
    - play1.c
    - udns.h
    - libudns.a
    by running: gcc play1.c -L. -ludns libudns.a -o play1

    And the resulting "play1" executable works ok.


    libudns.a has been compiled with library provided "configure", and its
    Makefile does contain -fPIC option:
    -------------------------------------------------
    PICFLAGS =3D -fPIC
    [..]
    c.lo:
    $(CC) $(CFLAGS) $(PICFLAGS) $(CDEFS) -o $@ -c $<
    -------------------------------------------------


    I'm a bit lost here, any help please?

    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Feb 5, 2011
    #1
    1. Advertising

  2. Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)

    2011/2/5 I=C3=B1aki Baz Castillo <>:
    > Hi, I must include a header (udns.h) and library (libudns.a) in a Ruby
    > C extension (Linux 64 bits).
    >
    > In extconf.rb I set:
    >
    > =C2=A0have_library("udns")


    I must add that if I install the Debian/Ubuntu package libudns-dev
    (which install both a dynamic libudns.so and a static libudns.a) then
    my Ruby C extension compiles correctly.

    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Feb 5, 2011
    #2
    1. Advertising

  3. Iñaki Baz Castillo

    Ralf Mueller Guest

    Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)

    On Sun, 6 Feb 2011 06:38:26 +0900
    I=C3=B1aki Baz Castillo <> wrote:

    > 2011/2/5 I=C3=B1aki Baz Castillo <>:
    > > Hi, I must include a header (udns.h) and library (libudns.a) in a
    > > Ruby C extension (Linux 64 bits).
    > >
    > > In extconf.rb I set:
    > >
    > > =C2=A0have_library("udns")

    >=20
    > I must add that if I install the Debian/Ubuntu package libudns-dev
    > (which install both a dynamic libudns.so and a static libudns.a) then
    > my Ruby C extension compiles correctly.
    >=20


    Try '-fPIC -DPIC'.

    regards
    ralf
     
    Ralf Mueller, Feb 7, 2011
    #3
  4. Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)

    2011/2/7 Ralf Mueller <>:
    > Try '-fPIC -DPIC'.


    Same error even if I've tryed that in the Makefile of libudns.a and
    also in the Ruby extension Makefile. Same output as before (but now
    with -DPIC):

    gcc -I. -I/usr/include/ruby-1.9.1/x86_64-linux
    -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I.
    -fPIC -DPIC -fno-strict-aliasing -g -g -O2 -fPIC -DPIC -o em-udns.o
    -c em-udns.c
    gcc -shared -o em_udns_ext.so em-udns.o -L. -L/usr/lib -L. -rdynamic
    -Wl,-export-dynamic -lruby-1.9.1 -ludns -lpthread -lrt -ldl -lcrypt
    -lm -lc
    /usr/bin/ld: ./libudns.a(udns_resolver.o): relocation R_X86_64_32
    against `dns_defctx' can not be used when making a shared object;
    recompile with -fPIC
    /libudns.a: could not read symbols: Bad value

    Thanks.



    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Feb 7, 2011
    #4
  5. Iñaki Baz Castillo

    Peter Zotov Guest

    Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)
     
    Peter Zotov, Feb 7, 2011
    #5
  6. Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)

    2011/2/7 Peter Zotov <>:

    Empty body :)


    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Feb 7, 2011
    #6
  7. Iñaki Baz Castillo

    Peter Zotov Guest

    Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)

    On Mon, 7 Feb 2011 21:52:18 +0900
    I=C3=B1aki Baz Castillo <> wrote:

    > 2011/2/7 Peter Zotov <>:
    >=20
    > Empty body :)
    >=20
    >=20


    Oh, sorry. That happens somehow. I hope that mailman upgrade will fix
    it. I was asking if you can post your code somewhere so we can get
    hands on it instead of blindly guessing.

    --=20
    WBR, Peter Zotov
     
    Peter Zotov, Feb 7, 2011
    #7
  8. Re: C extension: R_X86_64_32 problem when inlcuding a xxxxx.alibrary (64 bits SO)

    2011/2/7 Peter Zotov <>:
    > I was asking if you can post your code somewhere so we can get
    > hands on it instead of blindly guessing.


    Ok, I'll try to reduce my code and show it. Let me some time to do it.

    Thanks.

    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Feb 8, 2011
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GGG
    Replies:
    10
    Views:
    12,695
    Donar
    Jul 6, 2006
  2. sarmin kho
    Replies:
    2
    Views:
    847
    A. Lloyd Flanagan
    Jun 15, 2004
  3. Miki Tebeka
    Replies:
    1
    Views:
    455
    Marcin 'Qrczak' Kowalczyk
    Jun 14, 2004
  4. tkevans
    Replies:
    0
    Views:
    2,632
    tkevans
    Feb 11, 2009
  5. Jeff Thur

    Need to Format a zipcode into xxxxx-xxxx.

    Jeff Thur, Feb 18, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    195
Loading...

Share This Page