delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/05/15/07:52:57

From: colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters)
Subject: RE: Does any of you build successfully a DLL with B18?
15 May 1997 07:52:57 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <01BC6122.721CBE80.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Original-To: "'pascal DOT trouvin AT integralis DOT co DOT uk'" <pascal DOT trouvin AT integralis DOT co DOT uk>
Original-Cc: "'GNU-Win32'" <gnu-win32 AT cygnus DOT com>
Original-Sender: owner-gnu-win32 AT cygnus DOT com

pascal DOT trouvin AT integralis DOT co DOT uk wrote:
>     I've some problems with DLL creation since I've downloaded B18. I want 
>     to be sure that I've not missed somethng in the installation process.
>     
>     So in case that some of you have success with B18 and DLL creation, 
>     could you please send me, a little sample script?

This is for Mingw32 (and using the soon to be released 0.1.4 files, you
need your own DllMain in 0.1.3) so that may be a significant difference.
In any case here's the source:

--- dll.c ---

#include <windows.h>

int Add (int x, int y)
{
        printf ("In add!\nx = %d\ny = %d\n", x, y);
        return (x + y);
}


--- dll.def ---

EXPORTS
        Add


--- exe.c ---

#include <stdio.h>

int Add (int x, int y);

int main()
{
        int i, j, k;

        i = 10;
        j = 13;

        k = Add(i, j);

        printf ("i %d, j %d, k %d\n", i, j, k);

        return 0;
}

------

I use Jam to build my programs, but here are the commands it runs to build the
dll and executable from the above source:

# compile exe.c
gcc  -c  -O   -o exe.o  exe.c

# create import library for dll.dll
dlltool --dllname dll.dll  --def dll.def  --output-lib libdll.a  -k

# compile dll.c
gcc  -c  -O   -o dll.o  dll.c

# link dll.dll with relocation info (note the -dll option is defined in the
# mingw32 specs file to pass -dll to the linker and set the dll entry point
# appropriately, as well as link a different startup file dllcrt0.o into the
# dll).
gcc  -dll  -o junk.tmp -Wl,--base-file,base.tmp  dll.o
rm  junk.tmp
dlltool --dllname dll.dll  --base-file base.tmp --output-exp _temp.exp --def dll
..def
rm  base.tmp
gcc  -dll  -o dll.dll   dll.o    -Wl,_temp.exp
rm  _temp.exp

# link exe.exe from the source and using the import library. Also relocatable.
gcc  -L.  -o junk.tmp -Wl,--base-file,base.tmp  exe.o  libdll.a
rm  junk.tmp
dlltool --dllname exe.exe  --base-file base.tmp --output-exp _temp.exp
rm  base.tmp
gcc  -L.  -o exe.exe   exe.o  libdll.a   -Wl,_temp.exp
rm  _temp.exp

------

Running the resulting exe.exe produces the following (expected) output:

In add!
x = 10
y = 13
i 10, j 13, k 23

I've only tested on Win95.

The only thing I can notice in the source that you give is that your init
file will not invoke any constructors/destructors for global C++ objects
in the DLL. This shouldn't be a problem in your case though...

Good luck,

Colin.
-- Colin Peters - colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT jp
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019