Thread: static libraries

  1. #1
    Spam is Good
    Join Date
    Jan 2009
    Location
    In a cave on Mars
    Posts
    37

    static libraries

    Hi,

    I have a libX.a that I've created (from test.c) and put in /usr/lib/

    I've then created another libY.a, that calls functions in libX.a, I've also copied this lib to /usr/lib/

    Now when I write a program that uses both these libs, then compile I get:

    Code:
    bill@micosoftsux:~$ gcc test_prog.c  -Wall -m32 -O -g -lX -lY -o test_prog
    /usr/lib/libY.a(test.c.o): In function `test_init':
    test.c:(.text+0x111): undefined reference to `test_open'
    test.c:(.text+0x237): undefined reference to `test_open'
    /usr/lib/libY.a(test.c.o): In function `test_send':
    test.c:(.text+0x7e3): undefined reference to `test_write'
    test.c:(.text+0x8fc): undefined reference to `test_write'
    collect2: ld returned 1 exit status
    make: *** [test_prog] Error 1
    test.c header files exist in /usr/include/ and I've compiled with -lX -lY, but its not working...

    Any ideas?
    "What comes around, goes around"

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    test_open and test_write are in libX?

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    You could try something like "gcc -lX -lY -lX -lY <the rest of that stuff>" as it is a library processing issue -- there are three phases to the linking. If you don't include the second reference, phase two dies because of dependencies.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Quote Originally Posted by coletek View Post
    Hi,

    I have a libX.a that I've created (from test.c) and put in /usr/lib/

    I've then created another libY.a, that calls functions in libX.a, I've also copied this lib to /usr/lib/

    Now when I write a program that uses both these libs, then compile I get:

    Code:
    bill@micosoftsux:~$ gcc test_prog.c  -Wall -m32 -O -g -lX -lY -o test_prog
    /usr/lib/libY.a(test.c.o): In function `test_init':
    test.c:(.text+0x111): undefined reference to `test_open'
    test.c:(.text+0x237): undefined reference to `test_open'
    /usr/lib/libY.a(test.c.o): In function `test_send':
    test.c:(.text+0x7e3): undefined reference to `test_write'
    test.c:(.text+0x8fc): undefined reference to `test_write'
    collect2: ld returned 1 exit status
    make: *** [test_prog] Error 1
    test.c header files exist in /usr/include/ and I've compiled with -lX -lY, but its not working...

    Any ideas?
    Firt specify -lY and then -lX:
    Code:
    bill@micosoftsux:~$ gcc test_prog.c  -Wall -m32 -O -g -lY -lX -o test_prog
    Or use shared libraries

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    I remember now, having the same problem in Windows, so this is definitely GCC specific, not shared object / Linux.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C#] Intercept SysListView32 item added
    By Devils Child in forum Windows Programming
    Replies: 9
    Last Post: 03-26-2010, 07:29 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  4. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  5. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM