Mail Archives: cygwin/1999/03/18/16:08:54
Hi, there.
I find that the making of DLL's is a quite complicated and ennoying under
CygWin, so I decided to write a shell script to facilitate this task. Below
you will find this script. I would like much to hear from you about it.
I'm not a 'wizard' in things of such a kind, so I would be happy for any
comments and suggestions. Especially, I would like to here about this from
CygWin mantainers/developpers: do there are plans to include such a tool in
CygWin in the future releases, etc., etc.
At the same time I have two questions about DLL's:
1) Is it possible to use DLL's made by CygWin in applications being
developped with MSVC++ (may be after rebuilding the import library)? If
yes, how must I proceed for that (I am not at al specialist in MSVC++)?
2) The same questions in the case of C++ code. (I think that I have read
somewhere something about mangling scheme difference between CygWin g++ and
MSVC++, isn't it will be a problem?)
Well, that's all for the moment. Here goes the script:
------------------------------------------
#!/bin/sh
CC=gcc
EXT=c
# This script generates automatically DLLs on CygWin systems. By
# "generating DLL" I mean making the DLL itself (i.e., ".dll" file)
# and the import library for this dll (i.e., ".a" file). The script
# needs only the source of the DLL in C or in C++ and makes the
# two above-mentioned files.
#
# The usage is:
# makedll <xxx>
# where <xxx> is the name of the DLL you want to make without any
# extension.
#
# The source for the DLL is supposed to be in the file <xxx>.EXT,
# where the EXT can be set in the line 4 of this file (my default
# initial setting is c).
#
# This source file is also supposed to include windows.h
# #include <windows.h>
# to contain an empty
# int main(void){return 0;}
# function and a DLL entry function. The latter should be called
# 'startup', should be defined using the WINAPI attribute, should
# return 1 and should take three arguments:
# int WINAPI startup (HINSTANCE, DWORD, LPVOID)
# The minimum function looks like this:
# int WINAPI startup(HINSTANCE h, DWORD r, LPVOID f){return 1;}
#
# This script needs the following tools (normaly present on CygWin
# systems):
# echo, rm, nm, strip, dlltool.
# Clearly, it also needs the compiler (gcc or g++) for your (C or C++)
# code. To chose between gcc and g++ code edit the line 3 of this
# file (my default initial setting is gcc).
#
# Now we start making:
# First we make an ".o" file:
#
$CC -c $1.$EXT
# Second we try to genrate a ".def" file. For this we apply "nm" on
# the ".o" file, and then drop the useless (and may be even dangerous)
# main function:
#
echo EXPORTS > $1.def
nm $1.o | grep ' T _' | grep -v ' T _main$' | sed 's/.* T _//' >> $1.def
# Later we will also need to know the entry point of the dll. So, now
# we try to find it out and to keep it in a ".ent" file. For this we
# apply "nm" on the ".o" file, and then find in the output the line
# containing the entry point:
#
nm $1.o | grep ' T _startup.*@12$' | sed 's/.* T _/_/' | awk
'{printf"%s",$$1}' > $1.ent
# Now we have everything we need to make the ".dll" file. We do it
# as described in CygWin User's Guide:
#
$CC -s -Wl,--base-file,$1.base -o $1.dll $1.o -Wl,-e,`cat $1.ent`
dlltool --base-file $1.base --def $1.def --output-exp $1.exp --dllname $1.dll
$CC -s -Wl,--base-file,$1.base,$1.exp -o $1.dll $1.o -Wl,-e,`cat $1.ent`
dlltool --base-file $1.base --def $1.def --output-exp $1.exp --dllname $1.dll
$CC -Wl,$1.exp -o $1.dll $1.o -Wl,-e,`cat $1.ent`
# Personally, I prefere to strip everything to save disk space, but if
# you don't like it, comment the following line:
#
strip $1.dll
# It remains to make the ".a" file. We do it here as described in
# CygWin User's Guide:
#
dlltool --def $1.def --dllname $1.dll --output-lib $1.a
# Finally we clean out temporary files we have created:
#
rm -f $1.base $1.exp $1.o $1.def $1.ent
# That's all, Folks! :-)
------------------------------------------
Best regards,
Serguei.
___________________________________________________________________________
Serguei DACHIAN
Laboratoire de Statistique et Processus,
Universite du Maine, Av. Olivier Messiaen
72085 Le Mans CEDEX 9, FRANCE
Tel. : +33 (0)2 43 83 37 18
Fax. : +33 (0)2 43 83 35 79
E-mail : Serguei DOT Dachian AT univ-lemans DOT fr
WWW : http://www.univ-lemans.fr/sciences/statist/cvs/thesard.html#dachian
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
- Raw text -