1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

undefined refernece error when linking

Discussion in 'C' started by gcc, Dec 19, 2008.

  1. gcc

    gcc New Member

    Joined:
    Dec 19, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Dear all ,
    I have one shared library in "/usr/lib/ast/mod/quad.so"
    where the functions "X1" and "X2" are defined.
    In header file "quad.h" it is declared.
    I have created a "test.c" where X1 and X2 are called
    I have used the following commads for compiling and linking

    #gcc -c test.c
    #gcc -o test.o -L. -Wl,-rpath,/usr/lib/ast/mod/quad.so
    i am getting the error:
    undefined reference to X1
    undefined refernece yo X2

    what all things i have to do to make a proper linking
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Change the commas to spaces.
     
  3. gcc

    gcc New Member

    Joined:
    Dec 19, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    i tried with spaced but now unrecoginised command is coming.
    test.c
    -----------
    #include <stdio.h>
    #include <quad.h>
    int main(void)
    {
    X1 ();
    X2 ();
    return 0;
    }

    quad.h
    -----------
    extern void X1 ();
    void X2 ();
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What happens if you just try gcc test.c -o test /usr/lib/ast/mod/quad.so
     
  5. gcc

    gcc New Member

    Joined:
    Dec 19, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I used that and i got lot of undefined references errors are coming.
    when i use this i got only one undefined reference error.
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    No idea then, unless you fancy letting me know what errors you get.
     
  7. gcc

    gcc New Member

    Joined:
    Dec 19, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    the errors coming are:
    #gcc -o test test.o /usr/lib/ast/mod/quad.so
    /usr/lib/asterisk/modules/quad.so: undefined reference to `csel_get_next'
    /usr/lib/asterisk/modules/quad.so: undefined reference to `ast_cli_register_multiple'
    /usr/lib/asterisk/modules/quad.so: undefined reference to `ast_tv'
    /usr/lib/asterisk/modules/quad.so: undefined reference to `ast_pbx_start'
    /usr/lib/asterisk/modules/quad.so: undefined reference to `cm_load'

    like this lot of errors are coming.
    if usee the option which I posted first i got

    test.o: In function `main':
    test.c:(.text+0x12): undefined reference to `X1'
    test.c:(.text+0x26): undefined reference to `X2'
    collect2: ld returned 1 exit status
     

Share This Page