Creating (and linking against) a static library on AIX 5.3 using gcc/g++ - Aix

This is a discussion on Creating (and linking against) a static library on AIX 5.3 using gcc/g++ - Aix ; As per subject, I am trying to create a static library (libfoo.a) using gcc-3.4.6 (built from source) on AIX 5.3. I am trying to create the static library as follows: (source compiled into .o files) ar rcs ../lib/libfoo.a foo1.o foo2.o ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Creating (and linking against) a static library on AIX 5.3 using gcc/g++

  1. Creating (and linking against) a static library on AIX 5.3 using gcc/g++

    As per subject, I am trying to create a static library (libfoo.a) using
    gcc-3.4.6 (built from source) on AIX 5.3.

    I am trying to create the static library as follows:

    (source compiled into .o files)
    ar rcs ../lib/libfoo.a foo1.o foo2.o bar1.o bar2.o

    But then I am running into problems when trying to link an application
    statically against this libfoo.a created above:

    g++ testfoo.cpp -o testfoo -L../lib -lfoo

    ld: 0711-317 ERROR: Undefined Symbol: blah.o
    ld: 0711-317 ERROR: Undefined Symbol: bleh.o

    Where the undefined symbols are class member functions and/or regular C
    functions from the 4 object files compiled above into a static library.

    After wading through the archives, I tried passing in the "-bstatic"
    parameter to the AIX linker as follows:

    g++ testfoo.cpp -o testfoo -L../lib -Wl,-bstatic -lfoo

    and now I additionally get a lot more error messages:

    ld: 0711-317 ERROR: Undefined symbol: __loadx
    ld: 0711-317 ERROR: Undefined symbol: _exit
    ld: 0711-317 ERROR: Undefined symbol: disclaim
    ld: 0711-317 ERROR: Undefined symbol: .___memmove
    ld: 0711-317 ERROR: Undefined symbol: errno
    ld: 0711-317 ERROR: Undefined symbol: _system_configuration
    ld: 0711-317 ERROR: Undefined symbol: .___bzero
    ld: 0711-317 ERROR: Undefined symbol: open
    ld: 0711-317 ERROR: Undefined symbol: close
    ld: 0711-317 ERROR: Undefined symbol: klseek
    ld: 0711-317 ERROR: Undefined symbol: fstatx
    ld: 0711-317 ERROR: Undefined symbol: statx
    ld: 0711-317 ERROR: Undefined symbol: mntctl
    ld: 0711-317 ERROR: Undefined symbol: kfcntl
    ld: 0711-317 ERROR: Undefined symbol: kpwrite
    ld: 0711-317 ERROR: Undefined symbol: kwritev
    ld: 0711-317 ERROR: Undefined symbol: kwrite
    ld: 0711-317 ERROR: Undefined symbol: _nsleep
    ld: 0711-317 ERROR: Undefined symbol: _sigpending
    ld: 0711-317 ERROR: Undefined symbol: _sigaction
    ld: 0711-317 ERROR: Undefined symbol: _sigsuspend
    ld: 0711-317 ERROR: Undefined symbol: _setsid
    ld: 0711-317 ERROR: Undefined symbol: _setpgrp
    ld: 0711-317 ERROR: Undefined Symbol: blah.o
    ld: 0711-317 ERROR: Undefined Symbol: bleh.o
    [output snipped]


    Can someone please point out to me:

    (1) What I am doing wrong in creating the static library archive
    (libfoo.a)
    (2) What parameters need to be passed to the AIX linker to link
    statically against my libfoo.a library?

    gcc is configured as follows:

    gcc -v
    Reading specs from
    /usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/specs
    Configured with: ../configure -v --enable-languages=c,c++
    --enable-threads --with-as=/usr/bin/as --with-ld=/usr/bin/ld
    --with-system-zlib --disable-nls
    Thread model: aix
    gcc version 3.4.6


    Thanks!


  2. Re: Creating (and linking against) a static library on AIX 5.3using gcc/g++

    "fia_wrc_fanatic" writes:

    > As per subject, I am trying to create a static library (libfoo.a) using
    > gcc-3.4.6 (built from source) on AIX 5.3.


    Ok, that should be easy ...

    > I am trying to create the static library as follows:
    >
    > (source compiled into .o files)
    > ar rcs ../lib/libfoo.a foo1.o foo2.o bar1.o bar2.o


    Nothing wrong so far.

    > But then I am running into problems when trying to link an application
    > statically against this libfoo.a created above:
    >
    > g++ testfoo.cpp -o testfoo -L../lib -lfoo
    >
    > ld: 0711-317 ERROR: Undefined Symbol: blah.o
    > ld: 0711-317 ERROR: Undefined Symbol: bleh.o


    It would help if you post the *actual* message, not your recollection
    of it. I very much doubt that undefined symbols had '.o' in their
    names.

    > Where the undefined symbols are class member functions and/or regular C
    > functions from the 4 object files compiled above into a static library.


    No, they are not. If they were, you wouldn't be getting the error
    message that you are getting.

    It might help to run

    /usr/ccs/bin/nm -BC ../lib/libfoo.a | grep some_unresolved_symbol

    > After wading through the archives, I tried passing in the "-bstatic"


    Don't. Static linking is almost never the correct answer.

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

  3. Re: Creating (and linking against) a static library on AIX 5.3 using gcc/g++

    Paul Pluzhnikov wrote:
    >
    > > But then I am running into problems when trying to link an application
    > > statically against this libfoo.a created above:
    > >
    > > g++ testfoo.cpp -o testfoo -L../lib -lfoo
    > >
    > > ld: 0711-317 ERROR: Undefined Symbol: blah.o
    > > ld: 0711-317 ERROR: Undefined Symbol: bleh.o

    >
    > It would help if you post the *actual* message, not your recollection
    > of it. I very much doubt that undefined symbols had '.o' in their
    > names.
    >


    Paul,

    You are right... the error messages did not have '.o' in their names,
    instead the names were class member functions I think.

    Anyhow, I discovered my very stupid mistake shortly after posting to
    this group (go figure!):
    the source files I had compiled were #ifdef-ing out all the class
    declarations & definitions on AIX. The solution was to just add a
    "defined(_AIX)" to the existing "#if defined(..." lines in the source
    files.

    Thanks for your reply.
    Cheers,


+ Reply to Thread