Subject: Re: Building Relocatable DLLs on Win/95 (w/ cygwin B19)
From: [email-masked] (Mikey)

6 Dec 1998 23:16:31 -0800
Message-ID: <[email-masked]>
References: <199812041656.LAA12006@enormous>
Reply-To: [email-masked]
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: Chip Webb <[email-masked]>, [email-masked]

by specifying
$LIBPATH/libcygwin.a
you are telling ld to include all of the objects
in libcygwin.a in the link.
try
-L $LIBPATH/ -lcygwin
the --verbose option to ld can be used to diagnose
this kind of problem. its very um VERBOSE ;^)

To pass the --verbose option via gcc use -Wl,--verbose.
in general it is better to use gcc to link your images,
because it will take care of most of the details.

gcc -Wl,--dll,-e,$DLLENTRY,--base-file,$DLLNAME.base -o$DLLNAME.dll $DLLOBJS

this will automatically link in libcygwin.a libadvapi32.a libkernal32.a and libshell32.a
if any of them are needed.

Why libshell32.a? I have no idea.

On Fri, 4 Dec 1998 11:56:45 -0500, you wrote:

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

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".