Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3A048412.F650E99A@ece.gatech.edu> Date: Sat, 04 Nov 2000 16:48:02 -0500 From: Charles Wilson X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: cygwin AT sources DOT redhat DOT com Subject: Re: Building C++ DLLs References: <3A048147 DOT 7005DB68 AT ece DOT gatech DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit After spending a half hour writing this message, I just figured it out. The following procedure works: 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-dynamic -Wl,--output-def=cxxdll.def \ -Wl,--out-implib=libcxxdll.a -Wl,--enable-auto-image-base \ -o cxxdll.dll dllclass.o dllexterns.o Creating library file: libcxxdll.a c++ -c -I. -g -o usedll.o usedll.cc c++ -o usedll.exe -g usedll.o -L./ -lcxxdll ./usedll works! The difference was using '-Wl,--export-dynamic' instead of '-Wl,--export-all-symbols'. I didn't have to create the def file by hand or edit it; it "just works" (tm). --Chuck Charles Wilson wrote: > > 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 AT sourceware DOT cygnus DOT com -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com