DLL's and inlined methods

Mumit Khan khan@xraylith.wisc.EDU
Mon May 31 21:10:00 GMT 1999


"Schaible, Joerg" <Joerg.Schaible@gft.de> writes:
> Hello,
> 
> me again. I got trouble building a dll with classes that have inlined
> methods. I've modified Mumit's sample to demonstrate the problem:
> 
> // dllclass.h:
> 
> class DLLIMPORT
> DllClass : public DllClassBase {
> public:
>   DllClass (int i =3D 0);
>   ~DllClass ();
>   int non_virtual_method () const;
>   virtual int virtual_method () const;
> // =3D=3D=3D=3D=3D=3D=3D=3D Added inlined method here =
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>   int inline_method() const { for( int i =3D 40, j =3D 0; i--; ) j++; }
> #ifdef __GNUC__
>   DLLIMPORT             // work around an egcs-1.1 bug
> #endif
>   static int instances;
> private:
>   int i_;
> };
> 
> // dllclass.cc:
> 
> // added this function
> void dummy1()
> {
>     DllClass dc;
>     dc.inline_method();
> }
> 
> 
> // dllinline.cc  <=3D=3D Added new module to DLL
> 
> #include "dllclass.h"
> 
> void dummy2()
> {
>     DllClass dc;
>     dc.inline_method();
> }
> 
> 
> I will have following error message running make:
> 
> c++ -c -DBUILDING_DLL=3D1 -I. -g  -o dllclass.o dllclass.cc
> c++ -c -DBUILDING_DLL=3D1 -I. -g  -o dllexterns.o dllexterns.cc
> c++ -c -DBUILDING_DLL=3D1 -I. -g  -o dllinline.o dllinline.cc
> gcc -c -DBUILDING_DLL=3D1 -I. -g  -o dllinit.o dllinit.c
> dllwrap --export-all --output-def cxxdll.def --implib libcxxdll.a
> --driver-name c++ -o cxxdll.dll \
>         dllclass.o dllexterns.o dllinline.o dllinit.o
> Warning: no export definition file provided
> dllwrap will create one, but may not be what you want
> dllinline.o: In function `DllClass::inline_method(void) const':
> /egcs-1-1-2/dllhelpers-0.2.5/c++/dllclass.h:26: multiple definition of
> `DllClass::inline_method(void) const'
> dllclass.o(.text$inline_method__C8DllClass+0x0):/egcs-1-1-2/dllhelpers-0=
> .2.5
> /c++/dllclass.cc: first defined here
> collect2: ld returned 1 exit status
> dllwrap: c++ exited with status 1
> make: *** [cxxdll.dll] Error 1
> 

This is a bug in egcs-1.1.2 that shows up when dealing with inline 
methods in DLLs. The linkage directive is slightly wrong, and you end 
up with multiple definitions instead of the linker discarding duplicates 
as expected.

It's fixed in upcoming egcs-1.2 (please don't ask me when that'll be
released).

The workaround is to avoid inline methods is DLL exported/imported
classes. Define these out-of-line in .cc file and you should be all
set.

Regards,
Mumit


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



More information about the Cygwin mailing list