C++ noob - compiler question.

D

Denis Remezov

Noone said:
I'm not new to programming, but I am fairly new to C++. I've got a bit of a
problem with a project that I am working on. My environment is as follows:

OS: Mandrake 10
IDE: Anjuta
Compiler: gnu

The project I am working on is a C/C++ combo. I've created a class (in C++)
to encapsulate a particular bit of functionality; this class makes calls to
some C functions in a separate file (nothing complicated). All of the
necessary includes are in place.

The problem is this: when I "Compile" my file, it works fine and produces no
errors, but when I go to "Build" my file I get errors in the file that I
just compiled with no errors. The errors read "undefined reference to
function_name_here(param1*, param2)". The errors are produced on each line
that makes a call to a function in the C file.

See the FAQ (particularly item 32):
http://www.parashift.com/c++-faq-lite

Denis
 
N

Noone

I'm not new to programming, but I am fairly new to C++. I've got a bit of a
problem with a project that I am working on. My environment is as follows:

OS: Mandrake 10
IDE: Anjuta
Compiler: gnu

The project I am working on is a C/C++ combo. I've created a class (in C++)
to encapsulate a particular bit of functionality; this class makes calls to
some C functions in a separate file (nothing complicated). All of the
necessary includes are in place.

The problem is this: when I "Compile" my file, it works fine and produces no
errors, but when I go to "Build" my file I get errors in the file that I
just compiled with no errors. The errors read "undefined reference to
function_name_here(param1*, param2)". The errors are produced on each line
that makes a call to a function in the C file.

I'm a little confused as to what I need to do here. Why does it compile but
not build?

Thanks.

-Sheppe
 
V

Victor Bazarov

Noone said:
[...]
I'm a little confused as to what I need to do here. Why does it compile but
not build?

Get a decent book on gnu tools. You probably forget that for linking
you need to supply all object modules in the same command line.

BTW, compiler command lines are off-topic here. Please refer to
newsgroups comp.os.linux.development.* and gnu.g++.help for further
information.

V
 
M

Mike Wahler

Noone said:
I'm not new to programming, but I am fairly new to C++. I've got a bit of a
problem with a project that I am working on. My environment is as follows:

OS: Mandrake 10
IDE: Anjuta
Compiler: gnu

The project I am working on is a C/C++ combo. I've created a class (in C++)
to encapsulate a particular bit of functionality; this class makes calls to
some C functions in a separate file (nothing complicated). All of the
necessary includes are in place.

The problem is this: when I "Compile" my file, it works fine and produces no
errors, but when I go to "Build" my file I get errors in the file that I
just compiled with no errors. The errors read "undefined reference to
function_name_here(param1*, param2)". The errors are produced on each line
that makes a call to a function in the C file.

I'm a little confused as to what I need to do here. Why does it compile but
not build?

Look up "extern C". If that doesn't help, try creating
a small example that produces the problem and post it here
(standard code only, please).

-Mike
 
D

David Harmon

On Tue, 24 Aug 2004 18:08:50 GMT in comp.lang.c++, "Noone"
just compiled with no errors. The errors read "undefined reference to
function_name_here(param1*, param2)". The errors are produced on each line
that makes a call to a function in the C file.

Are you sure that you declared the function with
extern "C"
in the C++ part?

This issue is covered in Marshall Cline's C++ FAQ. See section
"[32] How to mix C and C++" It is always good to check the FAQ before
posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
 
S

Sheppe

As I replied to Mr. Wahler, doing this fixed things right up for me. Thanks!
:)

-Sheppe

David Harmon said:
On Tue, 24 Aug 2004 18:08:50 GMT in comp.lang.c++, "Noone"
just compiled with no errors. The errors read "undefined reference to
function_name_here(param1*, param2)". The errors are produced on each line
that makes a call to a function in the C file.

Are you sure that you declared the function with
extern "C"
in the C++ part?

This issue is covered in Marshall Cline's C++ FAQ. See section
"[32] How to mix C and C++" It is always good to check the FAQ before
posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
 

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

Forum statistics

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

Latest Threads

Top