New to C, "Undefined reference's"

S

steve

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
 
R

Richard Heathfield

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/
 
S

steve

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
 
R

Richard Heathfield

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).
 
S

santosh

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.

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 .
<<<<
 
M

Mark McIntyre

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top