help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined reference Error in compiling *.cpp with gcc


From: Ulrich Eckhardt
Subject: Re: undefined reference Error in compiling *.cpp with gcc
Date: Fri, 20 Jan 2006 17:47:39 +0100
User-agent: KNode/0.9.3

bozloo@gmail.com wrote:
> remove extern "C" in a.h, b.h

Glad you found a solution, but I would like to add some things:

- This has nothing to do with g++, any other C++ compiler would have given
you the same errors.
- Even though you don't strictly need it, you could have included "a.h"
into "a.cpp". The compiler then would have told you that the two
declarations conflict!
- You could also have added the extern "C" to the definitions in the .cpp
file.
- There is no need for an "extern" in front of a function declaration, you
only need to declare variables.

Removing the extern "C" is ok though, unless you want to make those files
usable in C. Then, you need to supply them to the C++ compiler and exclude
them for the C compiler:

#ifdef __cplusplus
extern "C"{
#endif
/* declarations here */
#ifdef __cplusplus
} // extern "C"
#endif

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]