Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* Problem linking C++ library with C program
@ 2001-01-11 18:11 bjb
  2001-01-11 20:24 ` Rajanish Calisa
  0 siblings, 1 reply; 2+ messages in thread
From: bjb @ 2001-01-11 18:11 UTC (permalink / raw)


Hi

I'm trying to create a C++ library that can be used by either a C or
C++ program.  The shared header file that the programs see accepts a
void *, which is internally cast to an object pointer.  After that my
library functions access the actual objects methods to perform the work
requested.

The shared header file is:

#ifdef __cplusplus
extern "C" {
#endif

void * Init(void);
void CleanUp(void *p);
void Display(void *p);

#ifdef __cplusplus
}
#endif


My initial experiment was successful.  I.e. I created a test library
that hid an object, which was indirectly accessed by my test C
program.  Inside the C++ library functions, I cast the void * to my
object:

void Display(void *p)
{
CNewClass *n = (CNewClass *) p;
cout << "The value is " << n->m_Value.c_str() << endl;
}

My object includes an STL string and the functions worked as I expected.

However, when I attempted to add an STL list member to my hidden object
(std::list<std::string> m_List;), suddenly, no matter what I tried, I
could not get the C program to link.  BTW, I'm not really sure how to
interpret the errors.

The link errors were (sorry about the length):

/usr/opt/osf1/usr/bin/ld:
Unresolved:
nullref__7__rwstd
nullref_initialized__7__rwstd
__as__Q13std60basic_string__TcQ13std15char_traits__TcQ13std13allocator__
TvXPCc
__ct__Q13std60basic_string__TcQ13std15char_traits__TcQ13std13allocator__
TvXPCcRCQ13std13allocator__Tv
erase__Q13std163list__TQ13std60basic_string__TcQ13std15char_traits__TcQ1
3std13allocator__TvQ13std80allocator__TQ13std60basic_string__TcQ13std15c
har_traits__TcQ13std13allocator__TvXQ23std163list__TQ13std60basic_string
__TcQ13std15char_traits__TcQ13std13allocator__TvQ13std80allocator__TQ13s
td60basic_string__TcQ13std15char_traits__TcQ13std13allocator__Tv8iterato
rQ23std163list__TQ13std60basic_string__TcQ13std15char_traits__TcQ13std13
allocator__TvQ13std80allocator__TQ13std60basic_string__TcQ13std15char_tr
aits__TcQ13std13allocator__Tv8iterator
deallocate_buffers__Q13std163list__TQ13std60basic_string__TcQ13std15char
_traits__TcQ13std13allocator__TvQ13std80allocator__TQ13std60basic_string
__TcQ13std15char_traits__TcQ13std13allocator__TvXv

The compile and link commands for the C program were:

cc -c -I../cpplib  ctest.c
cc -o ctest ctest.o  ../cpplib/libcpplib.a -lcxx

The compiler versions I am using are:

cc - System V Environment 4.0 (Digital 3.11)
cxx - DIGITAL C++ V6.1-027 on DIGITAL UNIX V4.0 (Rev. 1229)

I must have tried dozens of combinations of linking order and libraries
with libcxx.a, libcxxstd.a, .so, etc. but still no luck.  I would
appreciate any assistance, including an understanding of how to
interpret the link errors.

Thanks,

Bruce


Sent via Deja.com
http://www.deja.com/


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

* Re: Problem linking C++ library with C program
  2001-01-11 18:11 Problem linking C++ library with C program bjb
@ 2001-01-11 20:24 ` Rajanish Calisa
  0 siblings, 0 replies; 2+ messages in thread
From: Rajanish Calisa @ 2001-01-11 20:24 UTC (permalink / raw)


[*snip*]

>
> void Display(void *p)
> {
> CNewClass *n = (CNewClass *) p;
> cout << "The value is " << n->m_Value.c_str() << endl;
> }
>
> My object includes an STL string and the functions worked as I expected.
>
> However, when I attempted to add an STL list member to my hidden object
> (std::list<std::string> m_List;), suddenly, no matter what I tried, I
> could not get the C program to link.  BTW, I'm not really sure how to
> interpret the errors.
>
> The link errors were (sorry about the length):
>
> /usr/opt/osf1/usr/bin/ld:
> Unresolved:
> nullref__7__rwstd
> nullref_initialized__7__rwstd
>

[*snip*]

> cc -c -I../cpplib  ctest.c
> cc -o ctest ctest.o  ../cpplib/libcpplib.a -lcxx
>

Use the C++ compiler to link:

cc -c -I../cpplib  ctest.c
cxx -o ctest ctest.o  -L../cpplib/ -lcpplib

Make sure that the template instantiations present in cxx_repository
are put into the libcpp.a archive, alternatively you can create a
shared library using the command "cxx -shared -o libcpplib.so <object
files>";
This will automatically put all the instantiations in the shared
library. You did not get this problem when you used :string" because, the
instantiation of template basic_string<char> is present in libcxx.so. You
can verify that you will get linker errors with your original version if you
had compiled all you C++ files with -D__FORCE_INSTANTIATIONS.
Check the C++ headers for details on this.

Hope this helps.

rajanish...




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

end of thread, other threads:[~2001-01-11 20:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-11 18:11 Problem linking C++ library with C program bjb
2001-01-11 20:24 ` Rajanish Calisa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox