public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Loading cygwin dll's from non-cygwin applications (i.e., matlab)
@ 1999-06-25 11:55 Robert O. Morris
  1999-06-30 22:10 ` Robert O. Morris
  0 siblings, 1 reply; 2+ messages in thread
From: Robert O. Morris @ 1999-06-25 11:55 UTC (permalink / raw)
  To: cygwin
  Cc: Elaine Dobinson, Distributed Oceanographic Data Server, Robert Morris

Dear Cygwin Mailing List Participants:

Has anybody got _cygwin_ dynamic link libraries to execute
from within matlab (or any other non-cygwin application) ?

I've pretty much reviewed this mailing list to exhaustion
regarding getting a cygwin dll to run from matlab (i.e., a
"non-cygwin application").

It looked like a solution was in progress, but the conversation
stopped sometime in December.  I couldn't tell for sure
whether the conversation stopped because everybody gave up
or because a solution presented itself but didn't make
it to the mailing list (or anywhere else I could find).  I'm
guessing everybody gave up and pursued different avenues but
I really need to confirm this.  If this is the case, is there
any upcoming work that might solve the problem ?  Is it on
anybody's todo list ?

I saw the "--entry cygwin-noncygwin_dll_entry@12" which
made me think there was a solution - but to no avail - that
doesn't work.  I parred the code I stick into the dll down
to "main(){}", but no - it still doesn't run.  Matlab strips
its dll's of symbols, so debugging via gdb isn't going anywhere
I believe.  Maybe matlab can help me here - but I see nothing
regarding this in the technical archives on their web sites.

I used the information for mexing using cygwin from
http://www.physiol.ox.ac.uk/~mb3/gnumex20.html .  However,
those .bat's and mex.opts files, etc assume mingw32 (or whatever
the proper term for that is) and I changed that to use cygwin
with a small change to the .opts file.  Out of those scripts
I get my object file that I then feed into dlltool using
(among others) the cygwin_non_cygwin_dll_entry@12 entry point
provided for non-cygwin apps to enter the dll code.  The
above-mentioned url says you probably can't do what I'm trying
to do (I think "dangerous" was the term used) - but I'm forced
to try anyway.

My flags to dlltool match those provide by the java-ini example
provided by (excuse me if I'm wrong) Mumhit Kahn where he
explains how to build/use cygwin-compatible dynamic link libraries and the
flags used are pretty much exactly what is in the attached makefile
from that example.  I also used dlltool to create libraries (*.a's)
that, in-turn, call the matlab .dll's.  However, this isn't relevant for
the case where I stipped my code to just "main(){}".

Here's how I build exactly (/home/matlab is a cygwin link to //D/Matlabr11
aka d:\matlabr11 on my machine and loaddods.c is just "main(){}" at this
point)
----------------------------------------------------------------------------
--
BASH.EXE-2.02$ make loaddods
/home/matlab/bin/cmex.bat -c -g -DARCH_32BIT  -DHAVE_CONFIG_H -DUSE_LIBGXX_I
NLIN
ES -I. -I../../include -I/home/matlab/extern/include  -I/home/rmorris/data/b
uild
/DODS/packages-2.17/include -I/home/rmorris/data/build/DODS/packages-2.17/in
clud
e/w3c -I/usr/local/include loaddods.c
rm -rf loaddods.o
mv loaddods.obj loaddods.o
dllwrap --add-stdcall-alias -o loaddods.dll
loaddods.o -Wl,--entry,__cygwin_nonc
ygwin_dll_entry@12
Warning: no export definition file provided
dllwrap will create one, but may not be what you want
BASH.EXE-2.02$
----------------------------------------------------------------------------
---

Then I run this "loaddods.dll" from within matlab by cd'ng to the
appropriate
directory and

>> loaddods

The response by matlab is in the attached corel.jpg file.  That is,
the application crashes.

Porting the code to use mingw32 requires that each thing
I link with must also be ported (I believe) and it links
with a great deal - so this would be a very, very bad
time-consuming option (might as well have started out this
port of mine as a true "port", not one using UNIX emulation
via cygwin).  I must pursue getting it to work via the
cygwin unix emulation layer or choke and die trying :)

Can you shed light on my plight ?

Thank You !

Rob Morris
Jet Propulsion Laboratory












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

* Loading cygwin dll's from non-cygwin applications (i.e., matlab)
  1999-06-25 11:55 Loading cygwin dll's from non-cygwin applications (i.e., matlab) Robert O. Morris
@ 1999-06-30 22:10 ` Robert O. Morris
  0 siblings, 0 replies; 2+ messages in thread
From: Robert O. Morris @ 1999-06-30 22:10 UTC (permalink / raw)
  To: cygwin
  Cc: Elaine Dobinson, Distributed Oceanographic Data Server, Robert Morris

[-- Attachment #1: Type: text/plain, Size: 3888 bytes --]

Dear Cygwin Mailing List Participants:

Has anybody got _cygwin_ dynamic link libraries to execute
from within matlab (or any other non-cygwin application) ?

I've pretty much reviewed this mailing list to exhaustion
regarding getting a cygwin dll to run from matlab (i.e., a
"non-cygwin application").

It looked like a solution was in progress, but the conversation
stopped sometime in December.  I couldn't tell for sure
whether the conversation stopped because everybody gave up
or because a solution presented itself but didn't make
it to the mailing list (or anywhere else I could find).  I'm
guessing everybody gave up and pursued different avenues but
I really need to confirm this.  If this is the case, is there
any upcoming work that might solve the problem ?  Is it on
anybody's todo list ?

I saw the "--entry cygwin-noncygwin_dll_entry@12" which
made me think there was a solution - but to no avail - that
doesn't work.  I parred the code I stick into the dll down
to "main(){}", but no - it still doesn't run.  Matlab strips
its dll's of symbols, so debugging via gdb isn't going anywhere
I believe.  Maybe matlab can help me here - but I see nothing
regarding this in the technical archives on their web sites.

I used the information for mexing using cygwin from
http://www.physiol.ox.ac.uk/~mb3/gnumex20.html .  However,
those .bat's and mex.opts files, etc assume mingw32 (or whatever
the proper term for that is) and I changed that to use cygwin
with a small change to the .opts file.  Out of those scripts
I get my object file that I then feed into dlltool using
(among others) the cygwin_non_cygwin_dll_entry@12 entry point
provided for non-cygwin apps to enter the dll code.  The
above-mentioned url says you probably can't do what I'm trying
to do (I think "dangerous" was the term used) - but I'm forced
to try anyway.

My flags to dlltool match those provide by the java-ini example
provided by (excuse me if I'm wrong) Mumhit Kahn where he
explains how to build/use cygwin-compatible dynamic link libraries and the
flags used are pretty much exactly what is in the attached makefile
from that example.  I also used dlltool to create libraries (*.a's)
that, in-turn, call the matlab .dll's.  However, this isn't relevant for
the case where I stipped my code to just "main(){}".

Here's how I build exactly (/home/matlab is a cygwin link to //D/Matlabr11
aka d:\matlabr11 on my machine and loaddods.c is just "main(){}" at this
point)
----------------------------------------------------------------------------
--
BASH.EXE-2.02$ make loaddods
/home/matlab/bin/cmex.bat -c -g -DARCH_32BIT  -DHAVE_CONFIG_H -DUSE_LIBGXX_I
NLIN
ES -I. -I../../include -I/home/matlab/extern/include  -I/home/rmorris/data/b
uild
/DODS/packages-2.17/include -I/home/rmorris/data/build/DODS/packages-2.17/in
clud
e/w3c -I/usr/local/include loaddods.c
rm -rf loaddods.o
mv loaddods.obj loaddods.o
dllwrap --add-stdcall-alias -o loaddods.dll
loaddods.o -Wl,--entry,__cygwin_nonc
ygwin_dll_entry@12
Warning: no export definition file provided
dllwrap will create one, but may not be what you want
BASH.EXE-2.02$
----------------------------------------------------------------------------
---

Then I run this "loaddods.dll" from within matlab by cd'ng to the
appropriate
directory and

>> loaddods

The response by matlab is in the attached corel.jpg file.  That is,
the application crashes.

Porting the code to use mingw32 requires that each thing
I link with must also be ported (I believe) and it links
with a great deal - so this would be a very, very bad
time-consuming option (might as well have started out this
port of mine as a true "port", not one using UNIX emulation
via cygwin).  I must pursue getting it to work via the
cygwin unix emulation layer or choke and die trying :)

Can you shed light on my plight ?

Thank You !

Rob Morris
Jet Propulsion Laboratory













[-- Attachment #2: Makefile.nocyg --]
[-- Type: text/x-makefile, Size: 2368 bytes --]

#
# Sample makefile to create Java JNI with Cygwin b20.1 tools, but using
# Mingw runtime. 
# 
# See Makefile.cyg if you want to use -mno-cygwin and build a Cygwin JNI.
#
# Things you may need to change:
#   JDK_ROOT     -- location where you installed JDK
#   MINGW_EXTRA  -- location where you installed mingw-extra package.
#

CC = gcc 
CXX = c++

DEBUG = -g -Wall -O2
CXXFLAGS = $(DEBUG) -mno-cygwin
CFLAGS = $(DEBUG) -mno-cygwin
CPPFLAGS = -I. -I$(MINGW_INCDIR) -I$(JDK_ROOT)/include \
	   -I$(JDK_ROOT)/include/win32

MINGW_EXTRA = c:/mingw-extra
MINGW_INCDIR = $(MINGW_EXTRA)/include
MINGW_LIBDIR = $(MINGW_EXTRA)/lib

JDK_ROOT = c:/jdk1.1.7A

AS = as
DLLTOOL = dlltool
DLLWRAP = dllwrap

#
# Various targets to build.
#
DLL_NAME = hello.dll
DLL_EXP_DEF = hello.def

all: $(DLL_NAME)

#
# DLL related variables. These are used when building the DLL. See later.
#

# Some tools require special CPP macros when building a DLL (eg., _DLL etc).
# Here we don't need anything.

# DLL_CFLAGS = -DBUILDING_DLL=1 -D_DLL=1 
DLL_CFLAGS = 

# The default entry point defined by dllwrap is __cygwin_dll_entry@12 
# defined in libcygwin.a, but that's only appropriate for Cygwin apps,
# but since Java is a MSVC app, we need to provide a different entry
# point. Note the leading underscore and the trailing @12.
# The -s flag strips the DLL to shrink the size.

DLL_LDFLAGS = -L$(MINGW_LIBDIR) -s -mno-cygwin

# any extra libraries that your DLL may depend on.
DLL_LDLIBS = 

DLL_SRCS  = HelloWorldImp.cc
DLL_OBJS  = $(DLL_SRCS:.cc=.o)
DLL_OBJS := $(DLL_OBJS:.c=.o)

###
#
# Making DLL
#
###

DLLWRAP_FLAGS = --output-def $(DLL_EXP_DEF) \
	--add-stdcall-alias \
	--driver-name $(CC) \
	-mwindows --target=i386-mingw32 \
	$(IMAGE_BASE) 

$(DLL_NAME): $(DLL_OBJS)
	$(DLLWRAP) $(DLLWRAP_FLAGS) -o $(DLL_NAME) \
	    $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

#
# dependencies.
#

#
# default rules for building DLL objects. Note that client programs (ie.,
# the ones that *use* the DLL) have to be compiled without the DLL_CFLAGS
# flags.
#
.cc.o:
	$(CXX) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.c.o:
	$(CC) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $<

# Note that we omit the $(DLL_CFLAGS) for client programs.
usedll.o: %o: %c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

clean:
	-rm -f $(OBJS) $(DLL_OBJS) $(DLL_NAME) $(DLL_EXP_LIB) $(DLL_EXP_DEF) $(TESTPROGS)


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-25 11:55 Loading cygwin dll's from non-cygwin applications (i.e., matlab) Robert O. Morris
1999-06-30 22:10 ` Robert O. Morris

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).