delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/06/18/13:22:50

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-ID: <4167E34A802BD11196100060974FBFB73BAAB6@ATLANTIS>
From: John Mount <jmount AT esgear DOT com>
To: "'cygwin AT sourceware DOT cygnus DOT com'" <cygwin AT sourceware DOT cygnus DOT com>
Subject: How do you build dll's against C++ code for use in TCL
Date: Fri, 18 Jun 1999 13:21:12 -0400
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2232.9)

Love cygwin!  Anyway I followed you instructions on how to make 
.dll's from c files.  I can do this, but can't quite get it to work 
for c++ files (to be loaded into TCL).  Can anyone help?

Using information from your site and mailing lists I wrote the following
script:

CYGPATH1="c:/cygnus/cygwin-b20/H-i586-cygwin32"
CYGPATH2="c:/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32"
CYGLIBPATH="-L $CYGPATH1/lib -L CYGPATH2/lib"
TCLINC="-I $CYGPATH1/include -I $CYGPATH2/include"
LIBS="-ltcl80 -lcygwin"
# Compile source files:
g++ -c $TCLINC $NAME.cc
g++ -c init.cc
gcc -c fixup.c
# Make .def file:
echo EXPORTS > $NAME.def
nm $NAME.oo init.o fixup.o | grep '^........ [T] _' | sed 's/[^_]*_//' >>
$NAME.def
# Link DLL.
g++ -s -Wl,--base-file,$NAME.base -Wl,--dll -o $NAME.dll $NAME.oo init.o
fixup.o $LIBS -e _dll_entry AT 12
dlltool --as=as --dllname $NAME.dll --def $NAME.def --base-file $NAME.base
--output-exp $NAME.exp
g++ -s -Wl,--base-file $NAME.base $NAME.exp -Wl,--dll -o $NAME.dll $NAME.oo
init.o fixup.o $LIBS -Wl,-e,_dll_entry AT 12
dlltool --as=as --dllname $NAME.dll --def $NAME.def --base-file $NAME.base
--output-exp $NAME.exp
g++ -s $NAME.exp -Wl,--dll -o $NAME.dll $NAME.oo init.o fixup.o $LIBS
-Wl,-e,_dll_entry AT 12



where init.cc is:
#include <windows.h> 
extern "C" 
{
  int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);
};
int WINAPI dll_entry (HANDLE , 
		     DWORD reason,
		     void *)
{
  return 1;
}



and fixup.c is:
/* 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");




and $FILE.cc is:
#include <stdlib.h>
#include <tcl.h>
#include <iostream.h>
// all functions directly used or referenced demoted to C
extern "C" 
{
  int Hw_Init(Tcl_Interp *interp);
  int t_com(ClientData clientData, Tcl_Interp *interp,
            int argc, char *argv[]);
  int main();
};
class fred {
public:
  fred() { printf("hello\n"); };
};
int t_com(ClientData clientData, Tcl_Interp *interp,
          int argc, char *argv[]) {
  fred t;
  sprintf(interp->result,"Hello World");
  return TCL_OK;
}
int Hw_Init(Tcl_Interp *interp) {
  Tcl_CreateCommand(interp, "hw", t_com,
                     (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
  Tcl_PkgProvide(interp,"hw","1.0");
  return TCL_OK;
}
int main() {
}



This works.  But if I add a line like "cout << "hi\n"; everything dumps
core in TCL.  My guess is that I have not initted the C++ runtime 
environment, is there an incantation to do this?

Thanks,
  John Mount




--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


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