Re: mkmf, linking against a specific DLL on windows



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 -machine:x86 -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+[[:xdigit:]]+\s+[[:xdigit:]]+\s+/, '')
+ end
+ SYM[l.strip] = true
end
- SYM[l.strip] = true
end



--
Nobu Nakada


.



Relevant Pages

  • Re: Including modified SNTP component in the Release
    ... from a command line window <sysgen -p servers timesvc>. ... anything went wrong and if the DLL doesn't get output to your ... Microsoft Corporation ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windowsce.embedded)
  • Re: can I startup a service which is a dll that is not part of the OS image?
    ... Software Design Engineer, Windows CE ... Microsoft Corporation ... > article "Implementing a Network Service on Windows CE" implies that it is. ... > If I run it as a service, where should I store the dll? ...
    (microsoft.public.windowsce.app.development)
  • Re: Word 2000, stuck on requesting virus scan
    ... It may not be a DLL. ... > MSSPELL3.DLL Microsoft Speller Microsoft Corporation ... > OBALLOON.DLL Microsoft Office 2000 component Microsoft Corporation ... > WINWORD.EXE Microsoft Word for Windows Microsoft Corporation ...
    (microsoft.public.word.application.errors)
  • GCC Cygwin C++ DLL linking problem
    ... I have a Windows LIB/DLL that I need to link my GCC program with. ... the .def file. ... Note that a dump of the DLL does not have ... error for each function in the DLL, but I am able to compile and link as C ...
    (comp.lang.cpp)
  • Re: Dll Build
    ... I would use SOURCES to build such a DLL. ... > I am trying to build a class installer dll and I want to use a .def file to ... > the command line utility included with the SDK or the VC++ build enviroment? ... > about how to use a .def file in the VC++ IDE, but was unable to locate the ...
    (microsoft.public.development.device.drivers)

Loading