public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ program with C shared object?
@ 2001-12-28 11:27 Joshua Pollak
  2001-12-28 12:12 ` bjorn rohde jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Joshua Pollak @ 2001-12-28 11:27 UTC (permalink / raw)
  To: gcc-help

Hello,

I'm working on an x86 Linux system, and am having trouble getting a simple 
C++ executable to link to a C shared object. This is my first time writing 
a shared object or doing anything more complicated than HelloWorld in gcc.

Currently, the shared object compiles and links just fine, and the 
executable complies to an object just fine. The problem occurs when I try 
to link the two objects to create a shared object.

I am using this command line, which generated errors I have appended to the 
end of this message:

ld -L../ExceptionTest_DLL/ -o ExceptionTester main.o \ 
../ExceptionTest_DLL/libExceptionTest.so.0

I've done a fairly extensive web search, and as a result compiled both the 
library and the executable with gcc -fexceptions -frtti. I also understood 
from reading doc's and mailing lists that I need to include -lstdc++ when I 
link, but if I try that I get an error message saying '-lstdc++' could not 
be found. The library definitely does exist however.

Anyway, as it currently stands, I end up with a bunch of unresolved 
external errors, mostly regarding exception handling functions, which are 
used in the C++ application, but not in the C library.

Any help regarding this issue would be appreciated,

-Josh

Here is a log of the errors I'm seeing when I try to link the application 
with the library:

[jpollak@loki ExceptionTest_EXE]$ make
ld -L../ExceptionTest_DLL/ -o ExceptionTester main.o 
../ExceptionTest_DLL/libExceptionTest.so.0
ld: warning: cannot find entry symbol _start; defaulting to 080483e0
main.o: In function `testDLL(bool)':
main.o(.text+0x131): undefined reference to `terminate(void)'
main.o(.text+0x152): undefined reference to `__rethrow'
main.o(.text+0x15d): undefined reference to `__cp_pop_exception'
main.o(.text+0x16d): undefined reference to `__rethrow'
main.o(.text+0x17a): undefined reference to `__rethrow'
main.o(.text+0x181): undefined reference to `__start_cp_handler'
main.o(.text+0x1ef): undefined reference to `__cp_pop_exception'
main.o(.text+0x1f9): undefined reference to `terminate(void)'
main.o: In function `CustomErrorReport(char const *, int)':
main.o(.text+0x23c): undefined reference to `__eh_alloc'
main.o(.text+0x274): undefined reference to `__cp_push_exception'
main.o(.text+0x27c): undefined reference to `__throw'
main.o(.text+0x281): undefined reference to `terminate(void)'
main.o(.text+0x2a2): undefined reference to `__rethrow'
main.o(.text+0x2a9): undefined reference to `terminate(void)'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::terminate(void) const':
main.o(.gnu.linkonce.t.terminate__Ct12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0+0x49): 
undefined reference to `string_char_traits<char>::assign(char &, char const &)'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::assign(char const *)':
main.o(.gnu.linkonce.t.assign__t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0PCc+0x13): 
undefined reference to `string_char_traits<char>::length(char const *)'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::eos(void)':
main.o(.gnu.linkonce.t.eos__t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0+0x7): 
undefined reference to `string_char_traits<char>::eos(void)'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::replace(unsigned int, unsigned int, 
char const *, unsigned int)':
main.o(.gnu.linkonce.t.replace__t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0UiUiPCcUi+0x2b): 
undefined reference to `__out_of_range(char const *)'
main.o(.gnu.linkonce.t.replace__t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0UiUiPCcUi+0x79): 
undefined reference to `__length_error(char const *)'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::Rep::move(unsigned int, char const *, 
unsigned int)':
main.o(.gnu.linkonce.t.move__Q2t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0_3RepUiPCcUi+0x27): 
undefined reference to `string_char_traits<char>::move(char *, char const 
*, unsigned int)'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::Rep::copy(unsigned int, char const *, 
unsigned int)':
main.o(.gnu.linkonce.t.copy__Q2t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0_3RepUiPCcUi+0x27): 
undefined reference to `string_char_traits<char>::copy(char *, char const 
*, unsigned int)'
main.o: In function `__default_alloc_template<true, 0>::_Lock::~_Lock(void)':
main.o(.gnu.linkonce.t._._Q2t24__default_alloc_template2b1i05_Lock+0x2a): 
undefined reference to `__builtin_delete'
main.o: In function `__default_alloc_template<true, 0>::allocate(unsigned 
int)':
main.o(.gnu.linkonce.t.allocate__t24__default_alloc_template2b1i0Ui+0xda): 
undefined reference to `__rethrow'
main.o: In function `__malloc_alloc_template<0>::_S_oom_malloc(unsigned int)':
main.o(.gnu.linkonce.t._S_oom_malloc__t23__malloc_alloc_template1i0Ui+0x1a): 
undefined reference to `endl(ostream &)'
main.o(.gnu.linkonce.t._S_oom_malloc__t23__malloc_alloc_template1i0Ui+0x27): 
undefined reference to `cerr'
main.o(.gnu.linkonce.t._S_oom_malloc__t23__malloc_alloc_template1i0Ui+0x2c): 
undefined reference to `ostream::operator<<(char const *)'
main.o(.gnu.linkonce.t._S_oom_malloc__t23__malloc_alloc_template1i0Ui+0x37): 
undefined reference to `ostream::operator<<(ostream &(*)(ostream &))'
main.o: In function `ETException::~ETException(void)':
main.o(.gnu.linkonce.t._._11ETException+0x30): undefined reference to 
`exception::~exception(void)'
main.o(.gnu.linkonce.t._._11ETException+0x47): undefined reference to 
`__builtin_delete'
main.o: In function `ETException::ETException(void)':
main.o(.gnu.linkonce.t.__11ETException+0xd): undefined reference to 
`exception::exception(void)'
main.o(.gnu.linkonce.t.__11ETException+0x3d): undefined reference to 
`exception::~exception(void)'
main.o(.gnu.linkonce.t.__11ETException+0x4d): undefined reference to 
`__rethrow'
main.o(.gnu.linkonce.t.__11ETException+0x55): undefined reference to 
`terminate(void)'
main.o: In function `ETException::ETException(ETException const &)':
main.o(.gnu.linkonce.t.__11ETExceptionRC11ETException+0x55): undefined 
reference to `exception::~exception(void)'
main.o(.gnu.linkonce.t.__11ETExceptionRC11ETException+0x65): undefined 
reference to `__rethrow'
main.o(.gnu.linkonce.t.__11ETExceptionRC11ETException+0x6d): undefined 
reference to `terminate(void)'
main.o: In function `ETException type_info function':
main.o(.gnu.linkonce.t.__tf11ETException+0x10): undefined reference to 
`exception type_info function'
main.o(.gnu.linkonce.t.__tf11ETException+0x18): undefined reference to 
`exception type_info node'
main.o(.gnu.linkonce.t.__tf11ETException+0x27): undefined reference to 
`__rtti_si'
main.o(.gnu.linkonce.d.__vt_11ETException+0xc): undefined reference to 
`exception::what(void) const'
main.o: In function `exception::exception(exception const &)':
main.o(.gnu.linkonce.t.__9exceptionRC9exception+0xb): undefined reference 
to `exception virtual table'
main.o: In function `basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::~basic_string(void)':
main.o(.gnu.linkonce.t._._t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b1i0+0x33): 
undefined reference to `__builtin_delete'
make: *** [ExceptionTester] Error 1


-- 
Joshua Pollak       (617) 491-3474 x586
Software Engineer         joshp@cra.com
Charles River Analytics     www.cra.com
---------------------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ program with C shared object?
  2001-12-28 11:27 C++ program with C shared object? Joshua Pollak
@ 2001-12-28 12:12 ` bjorn rohde jensen
  2001-12-28 12:36   ` Joshua Pollak
  0 siblings, 1 reply; 5+ messages in thread
From: bjorn rohde jensen @ 2001-12-28 12:12 UTC (permalink / raw)
  To: Joshua Pollak, gcc-help

Hi,

 If you want to use the linker directly to link object files, you do
have
to tell it, where to find quite a few libraries, including the standard
libraries provided by a C++ compiler. I would suggest using the compiler
to drive the linker, that way it will handle this sort of thing for you,
and have it pass your special linker options to the linker.


Yours sincerely,

Bjorn

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ program with C shared object?
  2001-12-28 12:12 ` bjorn rohde jensen
@ 2001-12-28 12:36   ` Joshua Pollak
  2001-12-28 13:19     ` bjorn rohde jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Joshua Pollak @ 2001-12-28 12:36 UTC (permalink / raw)
  To: gcc-help

Thank you,

I finally got the program to compile by using gcc to call the linker, and 
specifying -lstdc++ as well. Now I have one more problem. My goal is to 
have the library call a callback function from the executable. This 
callback function will throw an exception, which will be caught by the 
function in the application that initially called the shared library. The 
goal is to create an Exception based error handling system, even though the 
shared object is written in C, not C++.

The same code base works as a Windows C DLL and C++ Program, so I'm sure 
I'm just missing a compiler flag or something.

Both the library and program are compiled with the command line options 
-fexceptions -frtti

But at the point where the exception should have been thrown, I only see 
the text, 'Aborted' on stdout, although that phrase is not in my source 
code at all.

Is the library having trouble calling the callback function, or is 
the  exception having trouble making its way through the C library back to 
the application?

Again, thanks to the response to the initial question, and thank you for 
any help you can lend me.

-Josh
At 09:10 PM 12/28/2001 +0100, bjorn rohde jensen wrote:
>Hi,
>
>  If you want to use the linker directly to link object files, you do
>have
>to tell it, where to find quite a few libraries, including the standard
>libraries provided by a C++ compiler. I would suggest using the compiler
>to drive the linker, that way it will handle this sort of thing for you,
>and have it pass your special linker options to the linker.
>
>
>Yours sincerely,
>
>Bjorn

-- 
Joshua Pollak       (617) 491-3474 x586
Software Engineer         joshp@cra.com
Charles River Analytics     www.cra.com
---------------------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ program with C shared object?
  2001-12-28 12:36   ` Joshua Pollak
@ 2001-12-28 13:19     ` bjorn rohde jensen
  2001-12-31  7:00       ` Joshua Pollak
  0 siblings, 1 reply; 5+ messages in thread
From: bjorn rohde jensen @ 2001-12-28 13:19 UTC (permalink / raw)
  To: Joshua Pollak; +Cc: gcc-help

Hi there,

 I can't claim to have tried anything like, what you are attempting,
and i can offer you little advise. Personally i have rather mixed
feelings about the idea of propagating exceptions through a C
library, someone on the list much more knowledgable, than i, will
hopefully comment on this. The aborted message, you see, could easily
be due to exception propagation problems. I believe, 'Aborted' is the
usual message produced, when abort() is called, which can happen due
to unhandled exceptions or incorrect exception specifications.
 I do not quite understand, why you want to propagate exceptions through
the C library. It ought to be quite a bit easier to make a C++ wrapper
for the library.

Yours sincerely,

Bjorn

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ program with C shared object?
  2001-12-28 13:19     ` bjorn rohde jensen
@ 2001-12-31  7:00       ` Joshua Pollak
  0 siblings, 0 replies; 5+ messages in thread
From: Joshua Pollak @ 2001-12-31  7:00 UTC (permalink / raw)
  To: shamus; +Cc: gcc-help

Bjorn,

Thank you very much for explaining the 'Aborted.' message, that was 
helpful. Wrapping the C library in question is fairly large, so wrapping it 
would take quite a bit of work. Also, the reason I'm asking is to create a 
C++ wrapper-library which uses exceptions directly, rather than wrap each C 
function with a C++ one.

Anyway, I may have explained this before, but the C library provides an 
error handling subsystem that allows you to provide a callback function to 
handle errors. I'd like to provide the library a callback that throws 
exceptions. A quick test showed this works in MS-VC++, but we wish the 
solution to be cross-platform, so I want the code to work on GCC as well.

Are there some compiler switches that GCC might automatically enable for 
C++ code and not for C code, that I should try?

>  I do not quite understand, why you want to propagate exceptions through
>the C library. It ought to be quite a bit easier to make a C++ wrapper
>for the library.
>
>Yours sincerely,
>
>Bjorn

-- 
Joshua Pollak       (617) 491-3474 x586
Software Engineer         joshp@cra.com
Charles River Analytics     www.cra.com
---------------------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-12-31 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-28 11:27 C++ program with C shared object? Joshua Pollak
2001-12-28 12:12 ` bjorn rohde jensen
2001-12-28 12:36   ` Joshua Pollak
2001-12-28 13:19     ` bjorn rohde jensen
2001-12-31  7:00       ` Joshua Pollak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).