From: mbrett AT cu DOT rpms DOT ac DOT uk (Matthew Brett) Subject: cygwin compiled DLLs 14 Dec 1998 06:58:31 -0800 Message-ID: <199812141114.LAA00924.cygnus.gnu-win32@cheetah.rpms.ac.uk> To: khan AT xraylith DOT wisc DOT edu, gnu-win32 AT cygnus DOT com Cc: lars DOT gregersen AT private DOT dk Dear Mumit / fellow DLL sufferers, Thanks for all your stuff on DLLs on the list, which has been very helpful. Sadly, though, I am still stuck trying to link a Cygwin DLL to a Visual C calling program (and also get a working matlab mex file from Cygwin, which was my main aim). I am using b20.1 on NT4 sp3 FAT, and VC++ 4.2. I think I have tried everything in the dllhelpers 0.2.1 package, and still get invalid memory references as soon as I try and access any DLL routine, from a VC binary. I've attached the very simple code that I have been using. Have I made some silly mistake somewhere? Should I expect this to work yet? I would be very very grateful for any further thoughts, as I am now stuck. Thanks a lot, Matthew Brett ----------------------------- For the attached code: Compile of vcdll, vcmain works fine with: $ mk_makedll.sh vcmain.c vcdll.c and ./vcmain runs without error. However, trying to compile vcmain.c in VC++ and link to the DLL created by mk_makedll.sh with: > vclink vcmain vcdll results in in a binary that runs, giving: "Entering DLL" followed by the error message: "The instruction at 0x77f6cc66 referenced memory at 0x00000010" -------------------------- Code: -------------------------- #! /bin/sh # mk_makedll.sh, based on Mumit Khan's dllhelper make file. # Script to compile relocatable DLL, a calling main program, # and link the relocatable DLL to the calling main program # First argument is file for main program (for linking to DLL) # Second argument is file for compiling to DLL main=${1%.[Cc]} croot=${2%.[Cc]} # Compile source files: gcc -c -DBUILDING_DLL=1 -I. -g -Wall -o ${croot}.o ${croot}.c gcc -c -DBUILDING_DLL=1 -I. -g -Wall -o dllinit.o dllinit.c # Make .def file: dlltool --export-all --output-def ${croot}.def \ ${croot}.o dllinit.o # Link DLL. dllwrap --def ${croot}.def --driver-name gcc -o ${croot}.dll \ ${croot}.o dllinit.o # Build the .a lib to link to: dlltool --dllname ${croot}.dll --def ${croot}.def \ --output-lib ${croot}.a # compile main gcc -c -I. -g -Wall -o ${main}.o ${main}.c # link dll function with main gcc -o ${main}.exe -g -Wall ${main}.o ${croot}.a ------------------ /* vcmain.c */ #include int main() { printf("Entering DLL\n"); dll_func(); printf("Leaving after DLL\n\n"); return(0); } ----------------- /* vcdll.c - test DLL function */ #include int dll_func() { printf("Now in DLL\n"); return(0); } ---------------- (dllinit.c is dllinit.c from Mumit Khan's dllhelper package) ----------------- @echo off rem vclink.bat rem BAT file to link GCC dll with VC++ program rem call with file name roots of main c file, and dll file name rem e.g vclink main vcdll (where main.c and vcdll.dll are the files required) set MAINFILE=%1% set DLLFILE=%2% set MSVC_ROOT=%MSVC_ROOT% set PATH=%MSVC_ROOT%\BIN;%PATH% set INCLUDE=%MSVC_ROOT%\INCLUDE;%INCLUDE% set LIB=%MSVC_ROOT%\LIB;%LIB% rem Compiler parameters cl -c %MAINFILE%.c rem Library creation command echo LIBRARY %DLLFILE%.dll > temp.def type %DLLFILE%.def >> temp.def lib /def:temp.def /machine:ix86 /OUT:temp.lib rem Linker parameters link %MAINFILE%.obj temp.lib /out:%MAINFILE%.exe - 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".