—— Where exceptions happen.


How-to: Build OCaml native code with MSVC 2005

Most Ocaml books, tutorials and lectures would stress its performance. OCaml’s optimizing compiler generates high-performance native code, which I cost a whole afternoon to build.I installed Ocaml 3.09.3 release, and read the “Readme.windows.txt”. I found these evil lines:

" Visual C++ version 6 or later. We use Visual C++ 2003.
The free download Visual C++ 2005 Express Edition works under
Windows 2000, but not under Windows XP because of the "manifest"
annotations on DLLs, which are not yet supported by OCaml.
So, please stick with the 2003 edition for the time being. "
But... I've installed the free Visual C++ 2005 Express Edition. ╮(﹀_﹀")╭ One way is uninstalling the free MSVC 2005 Express edition, then emule/bt a pirate and out-of-date MSVC 2003. the other is trying to find some workaround. I chose the latter.
After a long try-err process, I successfully build OCaml into native win32 code with MSVC 2005 version. following is the detail step-by-step:

0. make sure you've installed Ocaml for the port based on the Microsoft toolchain. This guide isn't for Cygwin port.

1. get Visual C++ 2005 Express Edition from Microsoft.com, It's free. and get it's SP1 too.

2. get Microsoft Macro Assembler 8.0 (MASM) Package from Microsoft.com. It's free also.

3. get Microsoft Windows Server 2003 R2 Platform SDK from Microsoft.com. It's free but require you pass the "Windows Genuine Advantage" test.(if you hate this test. you can easily find the SDK ISO on emule...*\(▔▽▔)/*)

4. install 1,2.3.

5. set the PATH environment variable: add "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\bin" into the PATH. you may need alter the path as your tools' real install directory.

6. set the LIB environment variable as "D:\Microsoft Platform SDK for Windows Server 2003 R2\Lib;C:\Program Files\Microsoft Visual Studio 8\VC\lib\" you may need alter the path too.

7. Thus you ocamlopt your .ml file, thus all of them. And on the seventh step you ended your work which you had made; and you rested on the seventh step from all your work which you had made. :-P

ps. this How-to guide is writen in an obviously imperative style. Let us rewrite it in functional style:
let PATH = "$Visual Studio$\VC\bin; $Visual Studio$\Common7\IDE"
let LIB = "$Platform SDK$\lib; $Visual Studio$\VC\lib"

Functional style is really short and clear. :-)

1 留言:

NullPointer 说...

I've update my OCaml version to 3.10.0..and if you reader still use 3.09.x, I recommend you updating now.:-)