Subject: RE: Does any of you build successfully a DLL with B18?
From: [email-masked] (Colin Peters)

15 May 1997 07:52:57 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BC6122.721CBE80.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Original-To: "[email-masked]'" <[email-masked]>
Original-Cc: "'GNU-Win32'" <[email-masked]>
Original-Sender: [email-masked]

[email-masked] 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 - [email-masked]
-- 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
"[email-masked]" with one line of text: "help".