cp**********@yahoo.com wrote:
Could some C++ guru help me please? I am trying to build an application
using gcc 3.2.3, that has a some classes using functions defined in
some C files in the same directory. If inside the C++ source file I
use:
extern "C"{
// C function declarations
}
//C++ code
Then I get all linker problems that such and such C function cannot be
resolved. Is
there a compiler flag(in addition to the directive above) that I need
to activate?
Any help would be greatly appreciated. Thanks in advance for your help.
Well, you didn't give any specifics, so here are some
generic tips for the GCC suite:
1) use 'gcc' to compile AND LINK 'C' programs (even
those with multiple object files and libs)
2) use 'g++' to compile AND LINK 'C++' programs (even
those with multiple object files and libs)
3) use 'g++' to link programs which mix 'C' and 'C++'
object files and libs.
Both 'gcc' and 'g++' provide default lib info and additional
link info to the linker depending on 'C', 'C++', or mixed
code.
In other words, if your Makefile is invoking the linker
directly, you should change it to invoke either 'gcc' or
'g++' based on the 3 tips above.
Normally, the function prototypes for the 'C' modules
would be in a header file (e.g. 'myCstuff.h") that
your 'C++' modules would '#include'. That header file
would include the 'extern "C"' block, e.g.
/* myCstuff.h */
#ifndef MYCSTUFF_H
# define MYSCTUFF_H
# include <some_header>
# include <another_header>
# include "local_header"
# include "another_local_header"
# ifdef __cplusplus
extern "C" {
# endif
/* defines, typedefs, macros, prototypes for C functions
* go here
*/
# ifdef __cplusplus
}
# endif
#endif
--------
// in somefile.cpp
#include "myCstuff.h"
Regards,
Larry