This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


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

Building C++ DLLs


Is it possible to build C++ DLL's using 'c++ -shared' (that is, ld
--shared) instead of dllwrap?

I'm running into two problems (experimenting with Mumit's dll-helpers)

First,

c++ -c -DBUILDING_DLL=1 -I. -g  -o dllclass.o dllclass.cc
c++ -c -DBUILDING_DLL=1 -I. -g  -o dllexterns.o dllexterns.cc
c++ -shared -Wl,--export-all-symbols -Wl,--output-def=cxxdll.def \
  -Wl,--out-implib=libcxxdll.a -Wl,--enable-auto-image-base \
  -o cxxdll.dll dllclass.o dllexterns.o
Cannot export _bss_end__: symbol not defined
Cannot export _bss_start__: symbol not defined
Cannot export _data_end__: symbol not defined
Cannot export _data_start__: symbol not defined
Creating library file: libcxxdll.a
collect2: ld returned 1 exit status
make: *** [cxxdll.dll] Error 1

Why is ld trying to export "_bss_end__" and friends? Those symbols are
not referenced anywhere by the source code.

So, try again.  Take the generated .def file from the previous failure,
and edit it by hand to remove "_bss_end__" and friends. Second problem:

c++ -shared \
  -Wl,--out-implib=libcxxdll.a -Wl,--enable-auto-image-base \
  -o cxxdll.dll cxxdll.def dllclass.o dllexterns.o

That works fine! But....try to compile the application that uses the
dll:

c++ -c -I. -g  -o usedll.o usedll.cc
c++ -o usedll.exe -g   usedll.o -L./ -lcxxdll
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-3/libgcc.a(tinfo.o): In function
`_rtti_class':
/cygnus/netrel/src/gcc-2.95.2-3/gcc/cp/tinfo.cc(.text+0x60): multiple
definition of `__rtti_class'
.//libcxxdll.a(d000064.o)(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [usedll.exe] Error 1

So, I do 'nm -a libcxxdll.a | grep rtti' and get:

00000000 I __imp____throw_type_match_rtti
00000000 I __imp____rtti_user
00000000 I __imp____rtti_si
00000000 T ___rtti_ptr
00000000 I __imp____rtti_ptr
00000000 T ___rtti_ptmf
00000000 I __imp____rtti_ptmf
00000000 T ___rtti_ptmd
00000000 I __imp____rtti_ptmd
00000000 T ___rtti_func
00000000 I __imp____rtti_func
00000000 T ___rtti_class
00000000 I __imp____rtti_class
00000000 T ___rtti_attr
00000000 I __imp____rtti_attr
00000000 T ___rtti_array
00000000 I __imp____rtti_array

Note that the importlib generated using the following command:

dllwrap --implib libcxxdll.a.wrap --driver-name c++ -o cxxdll.dll
cxxdll.def dllclass.o dllexterns.o

does not contain any rtti stuff (also, it seems to ignore cxxdll.def and
generate its own behind the scenes) and allows successfully link/usage
of the dll.

'nm -a libcxxdll.a.wrap | grep rtti' ---> no output

How can I generate a C++ DLL using c++ -shared (ld --shared) without
hand-editing a def file, and avoid this rtti garbage...(what is that,
anyway?)

Help...

--Chuck

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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