This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: build error -- can not find operator new

On Mon, 2007-11-05 at 01:49 -0800, Lin George wrote:

> 1. I have a shared library called wirtten in C++ and has C interface (extern C wrapper);
> 2. I have another shared called, which is written in C and is dependent on, and I am using -lA to build shared library and it is successful;
> 3. I have an application called C, which is written in C and is dependent on shared library, and when using -lB -lA to build the application C, here are the link error messages,

> For the whole process, I am using gcc other than g++. And I am wondering how to solve this issue in step 3?
> I think we are able to build C application with dependent C++ shared library, right?

Dont. The right solution is to make C a library replacing 'main"
with "mymain", link against B (and A if static or non-Elf dynamic).

Then make a trivial C++ program:

extern "C" int mymain(int argc, char **argv);
int main(int argc, char ** argv) { return mymain(argc, argv); }

and link it against library C. This allows the compiler to
include startup code special to C++ along with the mainline,
if any happens to be needed, eg for establishing exception handling.
It may also coerce the system to ensure the C++ core library
support is linked in, for example the code defining
operator new().

This is not guaranteed on arbitrary compilers, but it is
more likely to work correctly on any given compiler than
using a C mainline. 

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]