This is the mail archive of the 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]

Re[2]: Building C++ DLLs

Hello Charles,

Charles Wilson <> wrote on Sunday, November 05, 2000:

CW> After spending a half hour writing this message, I just figured it out.
CW> The following procedure works:

CW> c++ -c -DBUILDING_DLL=1 -I. -g  -o dllclass.o
CW> c++ -c -DBUILDING_DLL=1 -I. -g  -o dllexterns.o
CW> c++ -shared -Wl,--export-dynamic -Wl,--output-def=cxxdll.def \
CW>   -Wl,--out-implib=libcxxdll.a -Wl,--enable-auto-image-base \
CW>   -o cxxdll.dll dllclass.o dllexterns.o
CW> Creating library file: libcxxdll.a
CW> c++ -c -I. -g  -o usedll.o
CW> c++ -o usedll.exe -g   usedll.o -L./ -lcxxdll

CW> ./usedll works!

CW> The difference was using '-Wl,--export-dynamic' instead of
CW> '-Wl,--export-all-symbols'.  I didn't have to create the def file by
CW> hand or edit it; it "just works" (tm).

    I hope you already found your error: without --export-all-symbols,
and when there're __declspec(dllexport) symbols, very they are exported.
dllhelpers testcases have __declspec(dllexport) ;-) In fact,
--export-dynamic not used by pe code at all.

    So, without patch I posted on binutils lately, it won't be bright.
I scratched for some time to find out out the robust way to do it, and
found the only possibility to introduce context-sensetive filtering -
so, everything coming from libgcc.a should not be exported. However, I
missed with the second generalization - I thought that by not
exporting "reserved" two-underscored symbols I'll kill all those
__main, __DllMain*, etc. Unfortunately, that was too strict - c++
mangling uses __ as prefix somewhere, and even though such symbols
are dubbed "reserved", it doesn't mean that apps don't use them ;-)
I guess, correct solution would be to do only context filtering, but
add ?crt?.o there.

By filtering only libgcc.a, I get (junk is marked):

    _$_8DllClass @1
    _8DllClass$instances @2 DATA
>    _CRT_MT @3 DATA
    __12DllClassBase @4
    __8DllClassi @5
>    __CTOR_LIST__ @6 DATA
>    __DTOR_LIST__ @7 DATA
>    __builtin_delete @8 DATA
>    __do_global_ctors @9
>    __do_global_dtors @10 DATA
>    __main @11 DATA
>    __mingwthr_key_dtor @12
>    __rtti_si @13 DATA
>    __rtti_user @14 DATA
    __tf12DllClassBase @15
    __tf8DllClass @16
    __ti12DllClassBase @17 DATA
    __ti8DllClass @18 DATA
    _vt$12DllClassBase @19 DATA
    _vt$8DllClass @20 DATA
>    atexit @21
    global_dllclass1 @22 DATA
    global_dllclass2 @23 DATA
    global_int_variable @24 DATA
    non_virtual_method__C8DllClass @25
    virtual_method__C12DllClassBase @26
    virtual_method__C8DllClass @27

CW> --Chuck

Paul Sokolovsky, IT Specialist

Want to unsubscribe from this list?
Send a message to

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