This is the mail archive of the gcc-help@gcc.gnu.org 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]

C++ program with C shared object?


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
---------------------------------------


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