This is the mail archive of the cygwin@sourceware.cygnus.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]

Re: Some problems in making DLL's for C++ programs with GCC


Dear GNU development team,
Thanks to a reply (see below) from Gunther Ebert I was able to 
continue in my effort to try to make DLL's for C++ programs using
GCC (or g++ if you like) with the beta 17 release of Gnu-win32.
However, still some problems remain which I would like to indicate
below. Maybe someone could tell me what I am doing wrong, or otherwise
in case of an 'unexpected feature' one could fix it in the gnu-win32
package.
As I said before, I am developing C++ software for one of the large
LHC experiments at the particle accelerator center CERN
(Geneva, Switzerland) and if gnu-win32 is successfull the product
might be adopted as our standard worldwide, meaning we can get rid
of Microsoft C++ compilers on the user level.

                                       Thanks in advance,
                                       Nick van Eijndhoven

*----------------------------------------------------------------------*
 Dr. Nick van Eijndhoven                Department of Subatomic Physics
 email : nick@fys.ruu.nl                Utrecht University / NIKHEF
 tel. +31-30-2532331 (direct)           P.O. Box 80.000
 tel. +31-30-2531492 (secr.)            NL-3508 TA Utrecht
 fax. +31-30-2518689                    The Netherlands
 WWW : http://www.fys.ruu.nl/~nick      Office : Ornstein lab. 172
*----------------------------------------------------------------------*

> 
> 1) Put all your compiled c++ stuff into a library using ar
>    ar rc lib.a <objects>

==> This works without any problem, I however used 'ar rs' to get also 
    the symbol table included.
> 
> 2) generate the .def file from lib.a
>    echo EXPORTS > foo.def
>    nm lib.a | grep " [CT] " | sed '/ _/s// /' | awk '{print $3; }' >> foo.def
> 
==> The 'nm' pass works correctly. The 'grep' I could not use, since
    in the gnu-win32 there is only 'egrep'.
    Using the 'egrep' however gave me the correct output.
    Using the 'sed' pass I got an 'unknown command' error msg all the
    time from the sed.exe.
    However, since it is clear what 'sed' and 'awk' do, I did it by
    hand (=editing the produced file).

> 3) continue building the dll in the same manner like a C dll.
> 
==> and here the trouble started.

dlltool --def foo.def --output-exp foo.exp --output-lib lib.a --dllname foo.dll

--> this dlltool pass worked without problem.

ld -o foo.dll foo.exp *.o

--> here I got the following error msgs with the result that no .dll was created.
    The error msgs were :

    ...../LD.EXE: warning: cannot find entry symbol _mainCRTStartup:
                  defaulting to 00401000
    
    aap.o<.text +0x10>:aap.cc: undefined reference to `cout'
    ... and some more undef refs. to standard iostream stuff.

    where my lib.a consisted of aap.cc, noot.cc and mies.cc being just
    3 simple c++ functions doing nothing more than some stupid 'cout'.

    Note that in my lib.a (and consequently in the dll) I don't have a main()
    since I just want to have some (classes and member)functions in the lib.a
    and .dll to be used later by a variety of other (main) programs.
    From this I concluded that somehow the C library instead of the C++ library
    was searched in the ld step.
    I therefore tried :

g++ -o foo.dll foo.exp *.o

    This indeed removed the undefined references, however it created a new
    cryptic message which was something like :

    ..../i386-cygwin32/lib/libcygwin.a<libcmain.o>: In function `main':
    /pizza/mushroom/noer/beta17/src/winsup/libcmain.cc:30:
     undefined reference to `WinMain@16'

    This error message I really don't understand (note that I didn't provide
    a main() at all) and would appreciate if someone could help me out.
-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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