New to C, "Undefined reference's"

Discussion in 'C Programming' started by steve, Dec 2, 2007.

  1. steve

    steve Guest

    Hi, I am trying to compile a sample program using gcc. The program
    requires headers so I put the header files and corresponding source
    files into one folder. Then I ran the command 'gcc prog.c -o
    prog.exe.' It then gives me errors such as "undefined reference to
    '_N_VNew'" where N_VNew is in the header files I put in the folder.
    Usually gcc file.c -o file.exe worked for a c program that include no
    user defined headers. I've never dealt with headers before, is there
    some gcc command I need to use? btw, I doubt there is a problem in the
    source code calling the headers.

    Thank You
    steve, Dec 2, 2007
    #1
    1. Advertising

  2. steve said:

    > Hi, I am trying to compile a sample program using gcc. The program
    > requires headers so I put the header files and corresponding source
    > files into one folder. Then I ran the command 'gcc prog.c -o
    > prog.exe.' It then gives me errors such as "undefined reference to
    > '_N_VNew'" where N_VNew is in the header files I put in the folder.
    > Usually gcc file.c -o file.exe worked for a c program that include no
    > user defined headers. I've never dealt with headers before, is there
    > some gcc command I need to use? btw, I doubt there is a problem in the
    > source code calling the headers.


    You have asked question 13.25 in the comp.lang.c FAQ, which can be found at
    http://c-faq.com/

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Dec 2, 2007
    #2
    1. Advertising

  3. steve

    steve Guest

    Can someone give me an example, for instance, if I declare #include
    "aheader.h" in my program and aheader.h is in the same folder of
    myprog.c. I am in windows so I want to essentially run gcc myprog.c -o
    myprog.exe to make an exe file.

    Thank You
    steve, Dec 2, 2007
    #3
  4. steve said:

    > Can someone give me an example, for instance, if I declare #include
    > "aheader.h" in my program and aheader.h is in the same folder of
    > myprog.c. I am in windows so I want to essentially run gcc myprog.c -o
    > myprog.exe to make an exe file.


    This is not a header issue, as the FAQ I told you about should have made
    abundantly clear to you. "Undefined reference" generally means you've
    forgotten to link a library (although that is not the only possible cause
    of that message, it would seem to be the cause in this case, from what
    you've said so far).

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Dec 2, 2007
    #4
  5. steve

    santosh Guest

    steve wrote:

    > Can someone give me an example, for instance, if I declare #include
    > "aheader.h" in my program and aheader.h is in the same folder of
    > myprog.c. I am in windows so I want to essentially run gcc myprog.c -o
    > myprog.exe to make an exe file.


    From the draft Standard (n1256.pdf):

    >>>>>


    6.10.2 Source file inclusion (3)

    A preprocessing directive of the form

    # include "q-char-sequence" new-line

    causes the replacement of that directive by the entire contents of the
    source file identified by the specified sequence between the "
    delimiters. The named source file is searched for in an
    implementation-defined manner. If this search is not supported, or if
    the search fails, the directive is reprocessed as if it read

    # include <h-char-sequence> new-line

    with the identical contained sequence (including > characters, if any)
    from the original directive.

    <<<<

    Usually compilers look into the current directory when a double quotes
    form of the #include statement is encountered.

    You can also use the '-I' command line option with gcc to tell it to
    look into the corresponding directory. From the gcc manual:

    >>>>

    `-I DIR'
    Add the directory DIR to the list of directories to be searched
    for header files. Directories named by `-I' are searched before
    the standard system include directories. If the directory DIR is
    a standard system include directory, the option is ignored to
    ensure that the default search order for system directories and
    the special treatment of system headers are not defeated .
    <<<<
    santosh, Dec 2, 2007
    #5
  6. steve wrote:
    > Hi, I am trying to compile a sample program using gcc. The program
    > requires headers so I put the header files and corresponding source
    > files into one folder. Then I ran the command 'gcc prog.c -o
    > prog.exe.' It then gives me errors such as "undefined reference to
    > '_N_VNew'" where N_VNew is in the header files I put in the folder.


    The header only contains the declaration of that type. The definition is
    in some library. There's a FAQ which is relevant to this.

    By the way, you have a Greengrocer's apostrophe in your subject. Plurals
    do not generally require apostrophes.
    Mark McIntyre, Dec 2, 2007
    #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. Robb Smith
    Replies:
    2
    Views:
    570
    Saravana
    Jul 18, 2003
  2. =?Utf-8?B?UGF0cmljaw==?=

    Open new with new session

    =?Utf-8?B?UGF0cmljaw==?=, Dec 18, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    3,339
    tittlejoseph
    Sep 2, 2007
  3. Gawel
    Replies:
    1
    Views:
    394
    Alvin Bruney
    Dec 31, 2003
  4. =?Utf-8?B?QmVuamFtaW4=?=
    Replies:
    0
    Views:
    309
    =?Utf-8?B?QmVuamFtaW4=?=
    Feb 12, 2004
  5. Replies:
    2
    Views:
    450
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page