public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* dlopen a.exe
@ 2000-05-31  3:32 Jon Cook
  2000-05-31  6:34 ` Chris Faylor
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Cook @ 2000-05-31  3:32 UTC (permalink / raw)
  To: cygwin

Hi,

Can you use dlopen with the pathname set to 0 to open a.exe?
When I tried doing this with the code below, dlsym failed with "Win32
Error 127".

Thanks for any help,
Jon



#include <dlfcn.h>

float fn(float num)
{
  return num*5.0;
}

int main(void)
{
  void *hnd, *fnaddr;

  hnd= dlopen(0, RTLD_NOW);

  if (!hnd) {
    printf("Failed at dlopen - %s\n", dlerror());
    exit(1);
  }

  fnaddr= dlsym(hnd, "fn");

  if (!fnaddr) {
    printf("Failed at dlsym - %s\n", dlerror());
    exit(1);
  }
  
  printf("OK [%x]\n", fnaddr);
}

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

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

* Re: dlopen a.exe
  2000-05-31  3:32 dlopen a.exe Jon Cook
@ 2000-05-31  6:34 ` Chris Faylor
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Faylor @ 2000-05-31  6:34 UTC (permalink / raw)
  To: cygwin

On Wed, May 31, 2000 at 11:32:36AM +0100, Jon Cook wrote:
>Can you use dlopen with the pathname set to 0 to open a.exe?

No.  

cgf

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

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

* Re: dlopen a.exe
  2000-08-06 22:58   ` Brian D. Carlstrom
@ 2000-08-07  8:31     ` Jon Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Jon Cook @ 2000-08-07  8:31 UTC (permalink / raw)
  To: bdc; +Cc: cygwin, cygwin

>> "Brian" == Brian D Carlstrom <bdc@zurich.ai.mit.edu> writes:

Brian> Jon, if you still care and didn't figure it out, I can send you
Brian> a pointer to my magic to use the dlltool etc to make dlopen
Brian> work with a NULL first argument, which I stole from the tcl
Brian> port.

Thanks for the info. I've stopped working on the code that needed this
functionality, but if I pick it up again I'll let you know.

Cheers,
Jon

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

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

* Re: dlopen a.exe
  2000-08-06 21:02 ` Chris Faylor
@ 2000-08-06 22:58   ` Brian D. Carlstrom
  2000-08-07  8:31     ` Jon Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Brian D. Carlstrom @ 2000-08-06 22:58 UTC (permalink / raw)
  To: cygwin; +Cc: cookj, cygwin

Chris Faylor writes:
 > Regardless, you won't be able to retrieve anything with dlsym() unless
 > either the function/variable has been defined with the __declspec(dllexport)
 > attribute or you've included it in a linker .def file.

Aha! 

So I have a .def file...under B20. 

Under 1.1 (?) OSTYPE changed from cygwin32 to cygwin, so my Makefile
wasn't creating the .def file.

I use config.guess but it didn't catch this, because it uses:

    i*:CYGWIN*:*)
	echo i386-pc-cygwin32
	exit 0 ;;

I'm happy to get things updated especially because I removed the one
other "OSTYPE" cygwin32 hack I had, it was fixed with a cleanup of I/O
to apparently let "cat" be "cat" and not mess around with adding
carriage returns.

Jon Cook was probably trying to do the same thing I was, not really open
a.exe, but the current executable. I was trying to do it with a.exe as
well, because configure builds a.exe files. I do this in configure to
see if I need to prepend symbol names with an underscore, as well as to
see if the library automatically tries to do this.

Jon, if you still care and didn't figure it out, I can send you a
pointer to my magic to use the dlltool etc to make dlopen work with a
NULL first argument, which I stole from the tcl port.

Thanks again Chris. My bad.

-bri

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

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

* Re: dlopen a.exe
       [not found] <E13Ldqn-0008PJ-00@nestle.ai.mit.edu>
@ 2000-08-06 21:02 ` Chris Faylor
  2000-08-06 22:58   ` Brian D. Carlstrom
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Faylor @ 2000-08-06 21:02 UTC (permalink / raw)
  To: Brian D. Carlstrom; +Cc: cookj, cygwin

On Sun, Aug 06, 2000 at 08:45:17PM -0700, Brian D. Carlstrom wrote:
>This is from a while back, I haven't been on the list for a while, but
>I'm trying to upgrade a tool called scsh from cygwin-b20 and I came
>across this:
>
>Chris Faylor wrote: 
>> On Wed, May 31, 2000 at 11:32:36AM +0100, Jon Cook wrote:
>> > Can you use dlopen with the pathname set to 0 to open a.exe?
>> No.  
>> cgf
>
>huh? This used to work, and is required for my tool unless I want to
>totally rework it. I copied all sorts of crap with dlltool and gcc
>-Wl,scshvm.exp from the tcl port, as well as hacking my autocong
>configure script. 

Perhaps I misunderstood the question.  Take a look at the source code
for dlopen.  If you pass a NULL as the first parameter it returns a handle
to the current program, not an arbitrary program called "a.exe".

Regardless, you won't be able to retrieve anything with dlsym() unless
either the function/variable has been defined with the __declspec(dllexport)
attribute or you've included it in a linker .def file.

cgf

>This small program used to work. The mesage was old. Is there any way to
>do this now or am I going to have to stay with cygwin-b20 indefinitely?
>
>-bri
>
>#include <dlfcn.h>
>#include <stdio.h>
>fnord() 
>{ 
>  int i=42;
>}
>main() 
>{ 
>  void *self, *ptr1, *ptr2; 
>  self=dlopen(NULL,RTLD_LAZY);
>  if (self) { 
>    printf("foo\n");
>    ptr1=dlsym(self,"fnord"); 
>    ptr2=dlsym(self,"_fnord");
>    printf("ptr1 %x\n", ptr1);
>    printf("ptr2 %x\n", ptr2);
>    if(ptr1 && !ptr2) {
>      printf("bar\n");
>      exit(0); 
>    }
>    printf("qux\n");
>  } 
>  printf("baz\n");
>  exit(1); 
>} 

-- 
cgf@cygnus.com                        Cygnus Solutions, a Red Hat company
http://sourceware.cygnus.com/         http://www.redhat.com/

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

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

end of thread, other threads:[~2000-08-07  8:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-31  3:32 dlopen a.exe Jon Cook
2000-05-31  6:34 ` Chris Faylor
     [not found] <E13Ldqn-0008PJ-00@nestle.ai.mit.edu>
2000-08-06 21:02 ` Chris Faylor
2000-08-06 22:58   ` Brian D. Carlstrom
2000-08-07  8:31     ` Jon Cook

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