This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: build error -- can not find operator new
- From: Lin George <george4academic at yahoo dot com>
- To: skaller <skaller at users dot sourceforge dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 5 Nov 2007 02:24:53 -0800 (PST)
- Subject: Re: build error -- can not find operator new
Thanks John,
Your reply is great! I have two points which I am still confused.
1. Why the unresolved symbol occurs in step 3? I think in step 2, since I am building a shared library (not static library), and it should also solve any potential issues of symbol resolution (symbol export/import lookup). So, my point is if there are any truly unresolved symbols, the build should not be successful in step 2. But in step 2, the build is successful. Do you know why the unresolved symbol error occurs in step 3?
2. I have tried to replace gcc with g++ in step 3, and the build is successful. I have also performed some preliminary testing and it seems successful. How do you think of this solution?
regards,
George
----- Original Message ----
From: skaller <skaller@users.sourceforge.net>
To: Lin George <george4academic@yahoo.com>
Cc: gcc-help@gcc.gnu.org
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