Problem in making DLL's

Nick van Eijndhoven Nick@fys.ruu.nl
Tue Mar 18 09:38:00 GMT 1997


Dear GNU developers,
>From the Cygnus site I have taken the GNU-Win32 stuff and I am trying
to create a DLL from some simple C++ source files.
I am running windows95 and I use the beta 17.1 release
(gcc version cygnus-2.7.2-961023).
With the help of Gunther Ebert and Fergus Henderson I was able to
indeed create a DLL file via the procedure outlined in the file
'testdll.bat' below. However, the execution of the test program crashes
on a "cygwin exception handling error" after the correct printing
of "q defined". Could someone please help me out,
since in trying to use GCC as the standard in large high
energy physics experiments the matter is now becoming urgent.
Below I have included all the files I use, so that people can
reproduce the problems I encounter.
Note that when running everything via the static .a library
everything runs fine (as outlined in 'testlib.bat').
Another problem is that the standard C++ I/O stuff (like cout etc...)
are contained in the cygwin library. However, this poses problems
in linking (ld step) where in creating the dll one doesn't want
to drag in any main() or startup files from the cygwin lib.
I have circumvented this by giving my private main() (see the .bat file)
but I would prefer to have all standard C++ stuff (including I/O)
contained in stdc++.a (or g++.a if you like), so that only that lib
has to be linked in the DLL creation.
Note that I use g++ for the linking to avoid the need for giving all -L
paths for the standard libs. However, using 'ld' gives identical results.

Finally I would like to ask you whether the GNU-Win32 produced DLL's
are compatible with the Microsoft ones. I had the impression that they
indeed are and this compatibility is vital for our experimental groups
since we will have to use our GNU-Win32 produced DLL's together with
the ones produced with microsoft visual C++ (version 4.0).


                                              Thanks in advance,
                                                    Nick.

*----------------------------------------------------------------------*
 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
 ----------------------------------------------------------------------
 tel. +41-22-7679751 (direct)           CERN PPE Division / ALICE exp.
 tel. +41-22-7675857 (secr.)            CH-1211 Geneva 23
 fax. +41-22-7679480                    Switzerland
 CERN beep : 13+7294                    Office : B 160 1-012
*----------------------------------------------------------------------*

================== testdll.bat
@echo off
rem *** Script to create and test a GNU-Win32 DLL from *.cc files ***
rem --- Create a special file fixup.cc needed for the DLL ---
rem --- and to provide a 'fake' main to satisfy g++ ---
echo asm (".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0"); >fixup.cc
echo int main() {return 0;} >>fixup.cc
g++ -s -c Funcs.cc fixup.cc
ar rs q.a Funcs.o
echo EXPORTS >q.def
nm q.a | egrep " [CT] " | sed s/.........T._//g >q.scr
sed s/.........C._//g q.scr >>q.def
del q.scr
rem --- Create the export file to build the DLL ---
dlltool --def q.def --output-exp q.exp --dllname q.dll --output-lib q.a
rem --- Now actually create the DLL ---
g++ -s -nostartfiles -Wl,--image-base=0x0800000 -o q.dll fixup.o Funcs.o q.exp 
del fixup.cc
del fixup.o
del Funcs.o
del q.exp
del q.def
echo *** mkdll done, going for test ...
g++ -s -o test.exe test.cc q.a
test
del test.exe
del q.a
del q.dll
echo *** testing done. 

============== Funcs.h
// Definitions of the functions for private test program

class Funcs
{
 public:
  Funcs();
  void aap();
  void noot();
  void mies();
};

=============== Funcs.cc
#include <iostream.h>
#include "Funcs.h"

Funcs::Funcs() { }

void Funcs::aap()
{
 cout << "*** aap ***" << endl;
}

void Funcs::noot()
{
 cout << "*** noot ***" << endl;
}

void Funcs::mies()
{
 cout << "*** mies ***" << endl;
}

============== test.cc
// Main program to test the class Funcs by using the DLL
#include <iostream.h>
#include "Funcs.h"

void main()
{
 Funcs q;
 cout << "q defined" << endl;
 q.aap();
 cout << "aap invoked" << endl;
 q.noot();
 cout << "noot invoked" << endl;
 q.mies();
 cout << "mies invoked" << endl;
}

=============== testlib.bat
@echo off
rem *** Script to create and test a GNU-Win32 .a library from *.cc files ***
g++ -s -c Funcs.cc
ar rs q.a Funcs.o
del Funcs.o
echo *** Library created, going for test ...
g++ -s -o test.exe test.cc q.a
test
del test.exe
del q.a
echo *** testing done. 

-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list