Re: build error -- can not find operator new

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

 



Hi John,


One more comment to your solution, I want to confirm that for the trivial C++ program you mentioned below. We should build it with g++ other than gcc, right? Or else, the same issue in step 3 will be met again. :-)

> 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().


regards,
George

----- Original Message ----
From: skaller <skaller@xxxxxxxxxxxxxxxxxxxxx>
To: Lin George <george4academic@xxxxxxxxx>
Cc: gcc-help@xxxxxxxxxxx
Sent: Monday, November 5, 2007 6:03:35 PM
Subject: 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 libA.so wirtten in C++ and has C interface (extern C wrapper);
> 2. I have another shared called libB.so, which is written in C and is dependent on libA.so, and I am using -lA to build shared library libB.so and it is successful;
> 3. I have an application called C, which is written in C and is dependent on shared library libB.so, 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++: http://felix.sf.net

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux