Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > mkmf, linking against a specific DLL on windows

Reply
Thread Tools

mkmf, linking against a specific DLL on windows

 
 
Daniel Berger
Guest
Posts: n/a
 
      10-17-2005
Hi all,

Ruby 1.8.2
Windows XP
Free MS VC compiler

How do I link against a specific DLL on Windows again? I tried have_library,
but that always looks for the .lib file apparently.

I also tried $LDFLAGS += " -lfoo.dll", as well as "-link foo.dll" and "-l foo"
and "-link foo", but none of that seemed to work.

What's the correct way?

Thanks.

Dan


 
Reply With Quote
 
 
 
 
nobuyoshi nakada
Guest
Posts: n/a
 
      10-18-2005
Hi,

At Tue, 18 Oct 2005 02:16:42 +0900,
Daniel Berger wrote in [ruby-talk:160905]:
> How do I link against a specific DLL on Windows again? I tried have_library,
> but that always looks for the .lib file apparently.


What do you want to link against? AFAIK, VC link.exe can't
handle DLL files as input, without import library files (i.e.,
lib files).

--
Nobu Nakada


 
Reply With Quote
 
 
 
 
nobuyoshi nakada
Guest
Posts: n/a
 
      10-26-2005
Hi,

At Wed, 26 Oct 2005 07:42:03 +0900,
Daniel Berger wrote in [ruby-talk:162622]:
> Ok, but you can generate a .lib file from a .def, and you can generate
> a .def from a .dll. Here's a script I cobbled together that did the
> trick:


Of course you can, but I don't think it should be done
silently by mkmf.rb. It belongs to setting up of a particular
library, not building an extension for it.

> # Create a .def file from the results of a 'link -dump -exports'


Actually, it calls dumpbin.exe.

> # Create a .lib file from a .def file. Note that the lib command doesn't
> # seem to like long path names, so we'll shorten them.


Really?

$ lib -machine86 -def:../stable-build/i686-mswin32/msvcrt-ruby18.def -out:../stable-build/i686-mswin32/msvcrt-ruby18.lib
Microsoft (R) Library Manager Version 7.10.2240.8
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library ../stable-build/i686-mswin32/msvcrt-ruby18.lib and object ../stable-build/i686-mswin32/msvcrt-ruby18.exp

It's possible to tweak win32/mkexports.rb to accept DLL files
as well as object files.


Index: win32/mkexports.rb
================================================== =================
RCS file: /cvs/ruby/src/ruby/win32/mkexports.rb,v
retrieving revision 1.4
diff -U2 -p -u -r1.4 mkexports.rb
--- win32/mkexports.rb 18 Jun 2002 10:23:31 -0000 1.4
+++ win32/mkexports.rb 26 Oct 2005 02:19:04 -0000
@@ -4,13 +4,21 @@ SYM = {}

objs = ARGV.collect {|s| s.tr('/', '\\')}
-IO.foreach("|dumpbin -symbols " + objs.join(' ')) do |l|
- next if /^[0-9A-F]+ 0+ UNDEF / =~ l
- next unless l.sub!(/.*\sExternal\s+\|\s+/, '')
- if l.sub!(/^_/, '')
- next if /@.*@/ =~ l || /@[0-9a-f]{16}$/ =~ l
- elsif !l.sub!(/^(\S+) \([^@?\`\']*\)$/, '\1')
- next
+filetype = nil
+IO.foreach("|dumpbin -symbols -exports " + objs.join(' ')) do |l|
+ if (filetype = l[/^File Type: (.+)/, 1])..(/^\f/ =~ l)
+ case filetype
+ when /OBJECT/
+ next if /^[0-9A-F]+ 0+ UNDEF / =~ l
+ next unless l.sub!(/.*\sExternal\s+\|\s+/, '')
+ if l.sub!(/^_/, '')
+ next if /@.*@/ =~ l || /@[0-9a-f]{16}$/ =~ l
+ elsif !l.sub!(/^(\S+) \([^@?\`\']*\)$/, '\1')
+ next
+ end
+ when /DLL/
+ next unless l.sub!(/^\s*\d+\s+[[digit:]]+\s+[[digit:]]+\s+/, '')
+ end
+ SYM[l.strip] = true
end
- SYM[l.strip] = true
end



--
Nobu Nakada


 
Reply With Quote
 
nobuyoshi nakada
Guest
Posts: n/a
 
      10-26-2005
Hi,

At Wed, 26 Oct 2005 11:29:24 +0900,
nobuyoshi nakada wrote in [ruby-talk:162652]:
> It's possible to tweak win32/mkexports.rb to accept DLL files
> as well as object files.


Oops,

> +filetype = nil
> +IO.foreach("|dumpbin -symbols -exports " + objs.join(' ')) do |l|
> + if (filetype = l[/^File Type: (.+)/, 1])..(/^\f/ =~ l)
> + case filetype
> + when /OBJECT/


Forgot /LIBRARY/ here.

--
Nobu Nakada


 
Reply With Quote
 
Daniel Berger
Guest
Posts: n/a
 
      10-26-2005
nobuyoshi nakada wrote:
> Hi,
>
> At Wed, 26 Oct 2005 07:42:03 +0900,
> Daniel Berger wrote in [ruby-talk:162622]:
> > Ok, but you can generate a .lib file from a .def, and you can generate
> > a .def from a .dll. Here's a script I cobbled together that did the
> > trick:

>
> Of course you can, but I don't think it should be done
> silently by mkmf.rb. It belongs to setting up of a particular
> library, not building an extension for it.
>
> > # Create a .def file from the results of a 'link -dump -exports'

>
> Actually, it calls dumpbin.exe.


My research indicates that older compilers use dumpbin.exe, but the
more recent ones just use 'link -dump'. I don't have dumpbin.exe on my
machine for example, but I do have link.exe.

>
> > # Create a .lib file from a .def file. Note that the lib command doesn't
> > # seem to like long path names, so we'll shorten them.

>
> Really?
>
> $ lib -machine86 -def:../stable-build/i686-mswin32/msvcrt-ruby18.def -out:../stable-build/i686-mswin32/msvcrt-ruby18.lib
> Microsoft (R) Library Manager Version 7.10.2240.8
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> Creating library ../stable-build/i686-mswin32/msvcrt-ruby18.lib and object ../stable-build/i686-mswin32/msvcrt-ruby18.exp


Perhaps it has something to do with the version of lib.exe I have at
work, because I had to download it off the web. For whatever reason,
the most recent versions of the free compiler from MS don't seem to
include lib.exe by default any more. That, or I messed something up.
I *do* have it on my older laptop, but not on my desktop, for example
(which has a more recent version).

Someone please correct me if I'm wrong, but I couldn't find it in any
of the packages MS supplied.

> It's possible to tweak win32/mkexports.rb to accept DLL files
> as well as object files.


Cool, but you're going to have to make a check to see if dumpbin exists
and use link -dump instead if it doesn't.

Regards,

Dan

 
Reply With Quote
 
Daniel Berger
Guest
Posts: n/a
 
      10-26-2005
nobuyoshi nakada wrote:

<snip>

> > # Create a .lib file from a .def file. Note that the lib command doesn't
> > # seem to like long path names, so we'll shorten them.

>
> Really?
>
> $ lib -machine86 -def:../stable-build/i686-mswin32/msvcrt-ruby18.def -out:../stable-build/i686-mswin32/msvcrt-ruby18.lib
> Microsoft (R) Library Manager Version 7.10.2240.8
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> Creating library ../stable-build/i686-mswin32/msvcrt-ruby18.lib and object ../stable-build/i686-mswin32/msvcrt-ruby18.exp


Oh, you know what? I meant to say "path names with spaces in them".
Sorry, bad comment.

Regards,

Dan

 
Reply With Quote
 
nobuyoshi nakada
Guest
Posts: n/a
 
      10-26-2005
Hi,

At Wed, 26 Oct 2005 13:47:03 +0900,
Daniel Berger wrote in [ruby-talk:162672]:
> > > # Create a .def file from the results of a 'link -dump -exports'

> >
> > Actually, it calls dumpbin.exe.

>
> My research indicates that older compilers use dumpbin.exe, but the
> more recent ones just use 'link -dump'. I don't have dumpbin.exe on my
> machine for example, but I do have link.exe.


What version do you have?

With VC++2003, 'link.exe -dump' shows dumpbin.exe's message.

Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

usage: DUMPBIN [options] [files]

and putting -exports option before -dump, i.e., 'link.exe
-exports -dump' errs.

LINK : warning LNK4044: unrecognized option '/exports'; ignored
LINK : warning LNK4044: unrecognized option '/dump'; ignored

> Perhaps it has something to do with the version of lib.exe I have at
> work, because I had to download it off the web. For whatever reason,
> the most recent versions of the free compiler from MS don't seem to
> include lib.exe by default any more. That, or I messed something up.
> I *do* have it on my older laptop, but not on my desktop, for example
> (which has a more recent version).


Packaging miss? Also, msvcrt.lib was lost in VC++2003.

> Cool, but you're going to have to make a check to see if dumpbin exists
> and use link -dump instead if it doesn't.


Like this?

if path = ENV["PATH"]
path = path.split(File:ATH_SEPARATOR)
else
path = %w[.]
end
dumpbin = "dumpbin.exe"
unless path.find {|dir| File.join(dir, dumpbin)}
dumpbin = "link.exe -dump"
end

IO.foreach("|#{dumpbin} -symbols -exports " + objs.join(' ')) do |l|
...
end

--
Nobu Nakada


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help w/ linking an exec against a dll, vc++ 2005 ender.a.wiggins@gmail.com C++ 1 05-30-2008 07:55 AM
M$ against Blu-ray, M$ for Blu-ray, M$ against Blu-ray, M$ forBlu-ray, ...... Blig Merk DVD Video 66 04-27-2008 04:46 AM
OpenSSL problems with Ruby 1.8.4 and Windows - DLL linking listrecv@gmail.com Ruby 2 04-06-2006 09:20 PM
How to determine if a DLL is a COM DLL or .NET DLL Anushi ASP .Net 5 10-28-2004 01:59 PM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57