This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Linking c code with cpp code
- From: "HOLTZ, CORBIN L. (JSC-ER) (LM)" <corbin dot l dot holtz1 at jsc dot nasa dot gov>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 30 Oct 2003 08:09:14 -0600
- Subject: RE: Linking c code with cpp code
Make sure you are using the code below around your C function prototypes
that get included by your C++ code. Otherwise the C++ compiler will mangle
the C function names and result in a failed link. Also (I just ran into
this yesterday), if you want to call a C++ function from C (I was loading a
C++ plugin [*.so] into a C program) you can use the 'extern "C"' qualifier
in front of the C++ function declaration to keep the C++ compiler from
mangling the name of that specific C++ function.
#ifdef __cplusplus
extern "C" {
#endif
/* C Function prototypes */
#ifdef __cplusplus
}
#endif
-----Original Message-----
From: Agnar Renolen [mailto:agnar.renolen@emap.no]
Sent: Thursday, October 30, 2003 6:00 AM
To: gcc-help@gcc.gnu.org
Subject: Linking c code with cpp code
Hello,
I'm trying to integrate GNU Rx into a c++ program. But I can't link
them together.
I get an error something like:
<filename>.o(.text+0x72c):<filename>.cpp: undefined reference to
re_compile_pattern( ...)
when GCC tries to link the program.
It appears to me that when i compile regex.c with the C compiler, it
generates object code that is incompatible with the object code
generated by the C++ compiler, obviously due to the way the functions
are declared in regex.c
Is there a way to override these declarations so the c-compiler
generates object code that allows me to link them together?
Or is there a way I can make the linker link them together anyway.
Any suggestions?
Agnar Renolen
Trondheim
NORWAY