Linking shared libraries on HP-UX 11.11 - Unix

This is a discussion on Linking shared libraries on HP-UX 11.11 - Unix ; I'm seeing an akward problem. We have a library that works perfectly fine on HP-UX 11iv2 (IA64) but fails link with the same commands on 11iv1 (PA-RISC). Using g++ v4.2.1 I'm seeing the following: rm -f //libstdc++.a; ln -f -s ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Linking shared libraries on HP-UX 11.11

  1. Linking shared libraries on HP-UX 11.11

    I'm seeing an akward problem.
    We have a library that works perfectly fine on HP-UX 11iv2 (IA64) but
    fails link with the same commands on 11iv1 (PA-RISC).

    Using g++ v4.2.1 I'm seeing the following:

    rm -f //libstdc++.a; ln -f -s `g++ -print-file-name=libstdc++.a` /
    g++ temp/hpux_hppa_ilp32/a1.o temp/hpux_hppa_ilp32/a2.o temp/
    hpux_hppa_ilp32/a3.o -L/ -lpthread -o temp/hpux_hppa_ilp32/l.so -
    static-libgcc -shared -Wl,+e -Wl,AAa -Wl,+e -Wl,AAb -Wl,+e -Wl,AAc -Wl,
    +e -Wl,AAd -Wl,+e -Wl,AAe -Wl,+e -Wl,AAf -Wl,+e -Wl,AAg -Wl,+e -Wl,AAh
    /usr/ccs/bin/ld: DP relative code in file /var/tmp//ccaGAGtU.o -
    shared library must be position
    independent. Use +z or +Z to recompile.
    collect2: ld returned 1 exit status

    What goes on?

    When I try to add "-Wl,+Z" it says unrecognized command instead.

    Thanks.

    -- Henrik

  2. Re: Linking shared libraries on HP-UX 11.11

    hg@x-formation.com writes:

    > rm -f //libstdc++.a; ln -f -s `g++ -print-file-name=libstdc++.a` /
    > g++ temp/hpux_hppa_ilp32/a1.o temp/hpux_hppa_ilp32/a2.o temp/
    > hpux_hppa_ilp32/a3.o -L/ -lpthread -o temp/hpux_hppa_ilp32/l.so -
    > static-libgcc -shared -Wl,+e -Wl,AAa -Wl,+e -Wl,AAb -Wl,+e -Wl,AAc -Wl,
    > +e -Wl,AAd -Wl,+e -Wl,AAe -Wl,+e -Wl,AAf -Wl,+e -Wl,AAg -Wl,+e -Wl,AAh
    > /usr/ccs/bin/ld: DP relative code in file /var/tmp//ccaGAGtU.o -
    > shared library must be position
    > independent. Use +z or +Z to recompile.
    > collect2: ld returned 1 exit status


    You need to add '-fPIC' to the link line above.

    > What goes on?


    ld tells you that /var/tmp/ccaGAGtU.o was compiled without '-fPIC'.
    That file was produced by gcc during the link (likley it contains
    code to call your global ctors/dtors).

    > When I try to add "-Wl,+Z" it says unrecognized command instead.


    The '+Z' refers to *compiler* flag for HP cc/CC, which is equivalent
    to '-fPIC' for gcc.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  3. Re: Linking shared libraries on HP-UX 11.11


    > You need to add '-fPIC' to the link line above.
    >
    > ld tells you that /var/tmp/ccaGAGtU.o was compiled without '-fPIC'.
    > That file was produced by gcc during the link (likley it contains
    > code to call your global ctors/dtors).
    >


    Thanks! It worked instantly! I'm surprised though. I thought -fPIC
    option was reserved to the compiler only and not the linker.
    After all newer HP-UX, nor linux, mac osx, solaris or other unix
    doesn't requires it. It just works on those others without this
    switch.

    -- Henrik

  4. Re: Linking shared libraries on HP-UX 11.11

    hg@x-formation.com writes:

    >> You need to add '-fPIC' to the link line above.
    >>
    >> ld tells you that /var/tmp/ccaGAGtU.o was compiled without '-fPIC'.
    >> That file was produced by gcc during the link (likley it contains
    >> code to call your global ctors/dtors).
    >>

    >
    > Thanks! It worked instantly! I'm surprised though. I thought -fPIC
    > option was reserved to the compiler only and not the linker.


    That is correct.

    If you re-read my description above (pay attention this time ,
    you'll realize that in the process of linking shared library, gcc:
    1. creates a temporary source file
    2. *compiles* that into temporary object file (this is where -fPIC
    is required).
    3. invokes ld to perform the actual link. In your original link,
    ld complained that temporary object (generated in step 2) was
    not compiled in position-independent fashion.

    > After all newer HP-UX, nor linux, mac osx, solaris or other unix
    > doesn't requires it.


    Newer object file formats have better support for C++ and shared
    library initializers, so creating a temporary object isn't necessary
    and is not done [1]. However, adding '-fPIC' to link lines on these
    other platforms will not hurt.

    Cheers,

    [1] On AIX temporary is also created, but this didn't cause
    any problems for you because on AIX code is always compiled
    position-independent.
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  5. Re: Linking shared libraries on HP-UX 11.11


    > If you re-read my description above (pay attention this time ,
    > you'll realize that in the process of linking shared library, gcc:


    Thank you for the great explanation!

    -- Henrik



+ Reply to Thread