This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Building Relocatable DLLs on Win/95 (w/ cygwin B19)



Hi all,

I'm trying to build a relocatable DLL using cygwin B19 running on
Win/95 on a ThinkPad 770. I read the faq and the several other links
on the "Documentation" page, and am using the specific example given
in the FAQ. (I'm using B19, because it seems to be more stable)

Everything compiles and links properly, but when I execute main.exe, I
get a popup window entitled "Error Starting Program" and the message
is "Unable to run d:\dl\ex2\main.exe". Bash says "BASH.EXE: ./main:
Permission denied"

My Question is: 

	1) Should I expect this to work? If so, 

	2) What might I be doing wrong? 

	3) How might I debug/fix the problem?

I'm attaching the files and build script in case it helps.

Thanks!!!

Chip Webb

------------------------------------------------------------------------
--  main.c
------------------------------------------------------------------------
#include <stdio.h>

main()
{
  printf("doit(5)    returns %d\n",doit(5));
  printf("doittoo(3) returns %d\n",doittoo(3));
}
------------------------------------------------------------------------

------------------------------------------------------------------------
-- doit.c
------------------------------------------------------------------------
#include <stdio.h>

doit(int i)
{
  //  printf("in doit.c inside doit(%d)\n",i);
  return(doittoo(i));
}
------------------------------------------------------------------------

------------------------------------------------------------------------
-- doittoo.c
------------------------------------------------------------------------
#include <stdio.h>

doittoo(int i)
{
//  printf("in doittoo.c inside doittoo(%d)\n",i);
  return(i+10);
}
------------------------------------------------------------------------


------------------------------------------------------------------------
-- fixup.c
------------------------------------------------------------------------
/* This is needed to terminate the list of inport stuff */
/* Copied from winsup/dcrt0.cc in the cygwin32 source distribution. */
        asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0");
------------------------------------------------------------------------

------------------------------------------------------------------------
-- init.cc
------------------------------------------------------------------------
/* init.cc for WIN32.

   Copyright 1996 Cygnus Solutions

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#include <windows.h> 

extern "C" 
{
  int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);
};

int WINAPI dll_entry (HANDLE , 
                     DWORD reason,
                     void *)
{
  switch (reason) 
    {
    case DLL_PROCESS_ATTACH:
      break;
    case DLL_PROCESS_DETACH:
      break;
    case DLL_THREAD_ATTACH:
      break;
    case DLL_THREAD_DETACH:
      break;
    }
  return 1;
}
------------------------------------------------------------------------

------------------------------------------------------------------------
-- build (bash script)
------------------------------------------------------------------------
#! /bin/sh
######################################################################
#  Example Script to compile and link a relocatable DLL
#    Files that make up the DLL = foo.c foo2.c init.cc fixup.c.
#        (init.cc and fixup.c are housekeeping routines needed for the DLL. The actual
#                      library routines are in foo.c and foo2.c)
# ***Fill in your path to libcygwin.a here (with no trailing slash)***
######################################################################

######################################################################
# Compile source files:
######################################################################
LIBPATH=/cygnus/B19/H-i386-cygwin32/i386-cygwin32/lib
DLLNAME=test
DLLENTRY=_dll_entry@12

DLLSRCS="doit.c doittoo.c init.cc fixup.c"
DLLOBJS="doit.o doittoo.o init.o  fixup.o"

######################################################################
# Compile source files:
######################################################################
gcc -c $DLLSRCS

######################################################################
# Make .def file
######################################################################
echo EXPORTS                       >  $DLLNAME.def
nm doit.o doittoo.o init.o fixup.o | \
grep '^........ [T] _'             | \
sed 's/[^_]*_//'                   >> $DLLNAME.def

######################################################################
# Link DLL.
######################################################################

#---------------------------------------------------------------------
ld 		--dll                      \
   		-o          $DLLNAME.dll   \
   		            $DLLOBJS       \
   		            $LIBPATH/libcygwin.a \
   		-e          $DLLENTRY      \
	        --base-file $DLLNAME.base  

#---------------------------------------------------------------------
dlltool         --base-file  $DLLNAME.base \
                --def        $DLLNAME.def  \
                --output-exp $DLLNAME.exp  \
                --dllname    $DLLNAME.dll

#---------------------------------------------------------------------
ld 		--dll                      \
   		-o          $DLLNAME.dll   \
   		            $DLLOBJS       \
   		            $LIBPATH/libcygwin.a \
   		-e          $DLLENTRY      \
	        --base-file $DLLNAME.base  \
                            $DLLNAME.exp

#---------------------------------------------------------------------
dlltool         --base-file  $DLLNAME.base \
                --def        $DLLNAME.def  \
                --output-exp $DLLNAME.exp  \
                --dllname    $DLLNAME.dll

#---------------------------------------------------------------------
ld 		--dll                      \
   		-o          $DLLNAME.dll   \
   		            $DLLOBJS       \
   		            $LIBPATH/libcygwin.a \
   		-e          $DLLENTRY      \
                            $DLLNAME.exp


######################################################################
# Build the $DLLNAME.a lib to link to:
######################################################################
dlltool         --def        $DLLNAME.def  \
                --dllname    $DLLNAME.dll  \
                --output-lib $DLLNAME.a  

######################################################################
# Linking with main
######################################################################
gcc -c main.c 
gcc -o main main.o $DLLNAME.a 
------------------------------------------------------------------------

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]