public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* How do you build dll's against C++ code for use in TCL
@ 1999-06-18 10:21 John Mount
  1999-06-18 10:30 ` Mumit Khan
  1999-06-30 22:10 ` John Mount
  0 siblings, 2 replies; 4+ messages in thread
From: John Mount @ 1999-06-18 10:21 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

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@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@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@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@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do you build dll's against C++ code for use in TCL
  1999-06-18 10:21 How do you build dll's against C++ code for use in TCL John Mount
@ 1999-06-18 10:30 ` Mumit Khan
  1999-06-30 22:10   ` Mumit Khan
  1999-06-30 22:10 ` John Mount
  1 sibling, 1 reply; 4+ messages in thread
From: Mumit Khan @ 1999-06-18 10:30 UTC (permalink / raw)
  To: John Mount; +Cc: 'cygwin@sourceware.cygnus.com'

John Mount <jmount@esgear.com> writes:
> 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?

John, 

Your approach has unfortunately some pitfalls (eg., the Dll entry
point is wrong for Cygwin). Please check out the examples in my
dllhelpers package:

http://www.xraylith.wisc.edu/~khan/software/gnu-win32/dllhelpers.html

There are C, C++ and F77 DLL examples.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* How do you build dll's against C++ code for use in TCL
  1999-06-18 10:21 How do you build dll's against C++ code for use in TCL John Mount
  1999-06-18 10:30 ` Mumit Khan
@ 1999-06-30 22:10 ` John Mount
  1 sibling, 0 replies; 4+ messages in thread
From: John Mount @ 1999-06-30 22:10 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

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@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@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@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@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do you build dll's against C++ code for use in TCL
  1999-06-18 10:30 ` Mumit Khan
@ 1999-06-30 22:10   ` Mumit Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Mumit Khan @ 1999-06-30 22:10 UTC (permalink / raw)
  To: John Mount; +Cc: 'cygwin@sourceware.cygnus.com'

John Mount <jmount@esgear.com> writes:
> 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?

John, 

Your approach has unfortunately some pitfalls (eg., the Dll entry
point is wrong for Cygwin). Please check out the examples in my
dllhelpers package:

http://www.xraylith.wisc.edu/~khan/software/gnu-win32/dllhelpers.html

There are C, C++ and F77 DLL examples.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-06-30 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-18 10:21 How do you build dll's against C++ code for use in TCL John Mount
1999-06-18 10:30 ` Mumit Khan
1999-06-30 22:10   ` Mumit Khan
1999-06-30 22:10 ` John Mount

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).