Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Windows Vista/7 specific functions

15 views
Skip to first unread message

Reed Wilson

unread,
Sep 2, 2009, 12:43:46 AM9/2/09
to caml...@yquem.inria.fr
Hi all,
I am going to be writing a native-code 64-bit program which takes advantage
of some Windows Vista-only features (transactional NTFS), and I was
wondering how to get it working in OCaml. I have made numerous interfaces to
Windows XP functions, but the problem is that the NTFS transactional
functions are only available through MSVS 2008 and the Vista/7 SDKs, which
OCaml seems to not compile with. I tried using the new Windows 7 SDK tools
to compile the program to native code, but it kept giving me errors with not
being able to find bufferoverflowu.lib.

Does anybody know if there is any way to compile a 64-bit OCaml with the
newer Windows SDKs, or failing that, to at least tell OCaml how to properly
link things with them?

Thanks,
Reed

David Allsopp

unread,
Sep 2, 2009, 7:28:14 AM9/2/09
to caml...@yquem.inria.fr
Hi Reed,

Having hacked away with the Win64 port before I thought I’d have a go. The first thing I noticed is that Microsoft have finally released the x86 and x64 compilers in the same package (this was a pain if you wanted to build MSVC and MSVC64 ports as you needed two SDKs to do it...) – though I haven’t tried building the 32-bit MSVC port from this SDK yet.

Here’s what I did (you’ll have to excuse my idiosyncratic way of copying binary files into the OCaml tree – these can be replaced with PATH changes if you want. I copy things around so that ocamlopt always works without needing a special build environment or vast compiler suites permanently in my PATH).

The build is slightly complicated because you need to build flexdll directly.

Make sure you have Cygwin base with with Devel\make and Devel\subversion added

I installed the Win7 SDK to C:\Dev\WinSDK (though it still irritatingly puts the compilers in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC). I didn’t bother installing Documentation, Samples or the IA64 libraries.

Add the following to your LIB environment variable:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib\amd64;C:\Dev\WinSDK\lib\x64

Add the following to your INCLUDE environment variable:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\vc\include;C:\Dev\WinSDK\Include

Set OCAMLLIB to C:\Dev\OCaml-MSVC64\lib

A whole load of files now get copied to C:\Dev\OCaml-MSVC64\bin:

From C:\Cygwin\bin, copy cygpath.exe and cygwin1.dll (needed by flexlink)

Extract flexdll.h, default.manifest and flexlink.exe from the flexdll 0.19 x86 binaries (latest flexlink tool – doesn’t need to be x64)

From C:\Program Files (x86)\Microsoft Visual Studio\9.0\VC\bin\amd64, copy:

1033\clui.dll (this needs to be in C:\Dev\OCaml-MSVC64\bin\1033)

ml64.exe, cl.exe, c1.dll, c2.dll, cvtres.exe, link.exe and mspdb80.dll

From C:\Dev\WinSDK\Bin\x64, copy mt.exe

Or workaround that stupidity by having C:\Cygwin\bin and the other directories in your PATH

Start Bash (possibly as Administrator depending on permissions set on C:\Dev)

I placed the ocaml 3.11.1 tarball in C:\Dev\Src-MSVC64

Note that the sed instruction not only sets PREFIX but it also removes bufferoverflowu.lib from EXTRALIBS – apparently this is no longer needed in this version of the SDK (presumably the compiler has started to include all the required support natively or perhaps the runtime now has it).

$ cd /cygdrive/c/Dev/Src-MSVC64

$ svn co svn://frisch.fr/flexdll/trunk flexdll-dev

$ cd flexdll-dev

$ make CHAINS=msvc flexdll_msvc.obj flexdll_initer_msvc.obj

$ cp *.obj /cygdrive/c/Dev/OCaml-MSVC64/bin

$ cd ..

$ tar -xzf ocaml-3.11.tar.gz

$ cd ocaml-3.11

$ cp config/m-nt.h config/m.h

$ cp config/s-nt.h config/s.h

$ sed -e '20s/=.*$/=C:\/Dev\/OCaml-MSVC64/' -e '92s/=.*/=/' config/Makefile.msvc64 > config/Makefile

$ make -f Makefile.nt world opt opt.opt install

And you should have a fully working MSVC64 build with the Win7 SDK Compilers (and therefore be able to link against the newer libraries). If you wish, quite reasonably, to be a purist and have everything 64-bit you can now go back to flexdll-dev and say:

$ sed -i -e 's/"afxres.h"/<windows.h>/' version.rc

$ rc version.rc

$ cvtres /nologo /machine:amd64 /out:version_res.obj version.res

$ make version.ml

$ ocamlopt -o flexlink.exe -ccopt "-link version_res.obj" version.ml coff.ml cmdline.ml create_dll.ml reloc.ml

$ cp flexlink.exe /cygdrive/c/Dev/OCaml-MSVC64/bin

And you’ll have flexlink.exe as a 64-bit executable as well.

Best,

David

Omion

unread,
Sep 2, 2009, 7:19:34 PM9/2/09
to
Hi David,

Thanks for the quick response! I followed your instructions, but I was
still having problems. Then I realized that I had the 64-bit version
of flexlink 0.10 on the path, which gave some weird errors. So I
removed that from the path and used the 32-bit 0.19, and it compiled
perfectly! My problem initially was that I thought I had to use the 64-
bit one to link 64-bit programs, but you mentioned the 32-bit version
would work. So everything is up and running now.

Thanks again for your detailed instructions! Now all I have to do is
figure out how to use all these new functions ;)

Reed

0 new messages