how to compile

Discussion in 'C Programming' started by QQ, Oct 11, 2005.

  1. QQ

    QQ Guest

    sorry it might not belong to this board, but I don't know where else to
    post

    I have a c source file and a library, how should I compile under linux?
    I have using the command like


    gcc -o test -l lib.a main.c

    but it fails, displays like
    undefined reference to `ing'
    collect2: ld returned 1 exit status

    Thanks
     
    QQ, Oct 11, 2005
    #1
    1. Advertising

  2. QQ said:

    > sorry it might not belong to this board, but I don't know where else to
    > post
    >
    > I have a c source file and a library, how should I compile under linux?
    > I have using the command like
    >
    >
    > gcc -o test -l lib.a main.c


    Firstly, don't use test as a program name. test has a special meaning in
    Linux.

    Secondly, library names are traditionally in the form libfoo.a and are
    linked using -lfoo (dropping the lib and the .a because gcc just assumes
    them anyway). Note the absence of a space between -l and the library name.

    Thirdly, put the library information at the end of the line, not in the
    middle - for a library called libfoo.a use:

    gcc -o mylittleprogram main.c -lfoo

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/2005
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Oct 11, 2005
    #2
    1. Advertising

  3. QQ <> wrote:

    > I have a c source file and a library, how should I compile under linux?
    > I have using the command like


    > gcc -o test -l lib.a main.c


    > but it fails, displays like
    > undefined reference to `ing'
    > collect2: ld returned 1 exit status


    (Take it to comp.unix.programmer. Looks like you've got a linking
    problem.)

    Your post is off-topic for comp.lang.c. Please visit

    http://www.ungerhu.com/jxh/clc.welcome.txt
    http://www.eskimo.com/~scs/C-faq/top.html
    http://benpfaff.org/writings/clc/off-topic.html

    for posting guidelines and frequently asked questions. Thank you.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 11, 2005
    #3
  4. QQ

    QQ Guest

    Thank you very much!
     
    QQ, Oct 11, 2005
    #4
  5. QQ <> wrote:

    > Thank you very much!


    It is proper Usenet etiquette to include the relevant portions of the text
    you are replying to. To do this using Google groups, please follow the
    instructions below, penned by Keith Thompson:

    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 11, 2005
    #5
  6. QQ

    Guest

    QQ wrote:
    > sorry it might not belong to this board, but I don't know where else to
    > post
    >
    > I have a c source file and a library, how should I compile under linux?
    > I have using the command like
    >
    >
    > gcc -o test -l lib.a main.c
    >
    > but it fails, displays like
    > undefined reference to `ing'
    > collect2: ld returned 1 exit status
    >
    > Thanks


    Try it in the following way.
    gcc -o test main.c lib.a

    If you still get liking error, then we need to see what symbol is
    causing the error.

    Regards,
    Raju
     
    , Oct 12, 2005
    #6
    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. Nagaraj
    Replies:
    1
    Views:
    912
    Lionel B
    Mar 1, 2007
  2. timjowers
    Replies:
    7
    Views:
    4,416
    heyjude
    Feb 2, 2011
  3. Replies:
    1
    Views:
    467
    Cowboy \(Gregory A. Beamer\)
    Apr 11, 2008
  4. Carter
    Replies:
    2
    Views:
    527
    Carter
    Mar 4, 2009
  5. fAnSKyer
    Replies:
    2
    Views:
    565
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page