Compiling on Windows with MS VC Express 2008 and mr 3.6+

Shader discussion for beginners

Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Mon Feb 25, 2008 4:26 pm

Great news. It is now easier to set up a 32-bit Windows machine to compile shaders. I just prepared for training class using MS VC Express 2008 for mental ray version 3.6.52.4.

First of all, note that the most recent mental ray distributions have .msi installation executables that are different for different platforms. The installation now puts those by default into the directory with the platform name in it, for example,

ray-standalone-3.6.52.4-nt-x64.msi >> C:/Program Files/mental images/mental ray nt-x64/
ray-standalone-3.6.52.4-nt-x86-vc8.msi >> C:/Program Files/mental images/mental ray nt-x86-vc8/

The former is for 64-bit while latter will install a 32-bit windows version of mental ray that is compatible with MS Visual C++ version 8 (the one that came out with Express 2005). Express 2008 is actually MS VC9, but it will work with mental ray compiled with VC8. I wil note in a separate post how to work with 64-bit, which is also now doable if you load the extra platform SDK announced in February 2008.

So here's what I did to set up for compiling the mental ray training class for shader writing on a Windows XP platform. Assume we are setting up for compiling for the 32-bit nt-x86-vc8 platform.

1) First, download 2008 Express. Go to:
http://www.microsoft.com/express/download/

Then choose the download for Visual C++ 2008 Express Edition. It should be pretty fast (not like the long SDK downloads necessary for 2005 Express once figure out what you really need for compiling with it. Oops, now with SP1 it takes a bit longer.)

2) Copy io.h to unistd.h in C:\Program Files\Microsoft Visual Studio 9.0\VC\include. You may not need this depending on how you program. Those familiar Linux platforms and gcc might use unistd.h for low-level io. And you will need to do this if you are using sources from Andy Kopra's book, Writing mental ray Shaders.

3) Next, we set up the command line for rendering.
a) option 1. Reusing a desktop shortcut of the VS9 Command Prompt. The following makes a convenient desktop icon.
Click right on Start>All Programs>Visual C++ 9.0 Express Edition>Visual Studio Tools>Visual Studio 2008 Command Prompt
In that menu, choose Send to > Desktop (Create Shortcut) and rename the "Start in:" property to your shader directory.

That should take care of most of the VS env variables. Now for mental ray, add these environment variables:

Code: Select all
INCLUDE C:\Program Files\mental images\mental ray nt-x86-vc8\include

LIB C:\Program Files\mental images\mental ray nt-x86-vc8\lib;


Then, append the bin (executable) directory to end of existing PATH value:
Code: Select all
PATH <existing PATH value>;C:\Program Files\mental images\mental ray nt-x86-vc8\bin


If you are using the demo installation from Andy Kopra's book, Writing mental ray Shaders, the files may be located in C:\Program Files\mental images\mental ray Demo 32-Bit Edition\ instead of C:\Program Files\mental images\mental ray nt-x86-vc8\

b) option 2, Use the generic Command Prompt instead of the VS9 Command Prompt. We have to add the extra VS9 paths to the
environment variables:

Code: Select all
INCLUDE C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include;C:\Program Files\mental images\mental ray nt-x86-vc8\include

LIB C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files\mental images\mental ray nt-x86-vc8\lib;


And append to end of existing PATH value:
Code: Select all
PATH <existing PATH value>;C:\Program Files\mental images\mental ray nt-x86-vc8\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin



4) Compiling options for command line rendering. With VC 8 or VC 9, you must now use the mt command for building the manifest into the dll. Simply put, the dll will have built into it knowledge of where to find files on which it depends. In the manual that comes with mental ray, for NT x86, VC, it specifies the cl and link,

Code: Select all
cl /c /O2 /G6 /MD /nologo /W3 -DWIN_NT example.c
link /nologo /nodefaultlib:LIBC.LIB /OPT:NOREF /INCREMENTAL:NO /DLL /OUT:example.dll example.obj shader.lib


but not the mt command. So for NT x86, VC, for class we use:

Code: Select all
cl /c /O2 /MD /nologo /W3 -DWIN_NT example.c
link /nologo /nodefaultlib:LIBC.LIB /OPT:NOREF /INCREMENTAL:NO /DLL /OUT:example.dll example.obj shader.lib
mt.exe -nologo -manifest example.dll.manifest -outputresource:example.dll;2


Note that I removed the /G6, because it gave an ignored warning on my platform with 2008 Express (VC9).
Note that there are quite a few more flags indicated in the build .bat files in the base shader source (which is installable from the msi. See Custom install option.) They are not all necessary, as some have built up from legacy code . If you wanted to add a few extra flags, you might try:
/GF /GS- -D_SECURE_SCL=0

One last note, if you are compiling C++ files, we would typically add these two flags to cl: /TP /EHsc. For example,

Code: Select all
cl /TP /c /O2 /MD /nologo /W3 /EHsc -DWIN_NT example.c
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Mon Feb 25, 2008 5:36 pm

OK. Now for 64-bit compiling for 2008 Express, you also have to load the Windows SDK, namely Microsoft Windows SDK for Windows Server 2008 and .NET Framework 3.5. You can get it here:

http://www.microsoft.com/downloads/deta ... laylang=en

Now this one takes a long time to download, multiple hours on my Windows XP 64 machine. I ran it overnight after giving up watching it install.

Also, to do native compiling, make sure you do the 2008 Express before the Windows SDK download. Otherwise, it will just be a cross compile according to what I've read.

Now, for the command prompt, I re-use the Windows SDK command prompt that gets installed.
Start>All Programs>Microsoft Windows SDK v6.1> CMD Shell

And then type in:
setenv /x64
or
setenv /release /x64

if I want to use release options rather than debug default options

Now, for 64-bit I add the extra command line cl flag -DBIT64, and otherwise keep them the same as above, eg
Code: Select all
cl /c /O2 /MD /nologo /W3 -DWIN_NT -DBIT64 example.c

or for C++ cpp files:
Code: Select all
cl /TP /c /O2 /MD /nologo /W3 -DWIN_NT /EHsc -DBIT64 example.c


The link and mt commands will be the same as the 32-bit.

Note also that the path to the BIN, INCLUDE, and LIB directories will be different for this install:
C:/Program Files/mental images/mental ray nt-x64/
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Wed Jul 30, 2008 2:24 pm

BTW, ever wonder what that ";2" is at the end of the mt command's arguments.

It is an indicator that the manifest information goes into a dll. If it were a ";1", it is for putting the manifest into a exe.

See this for developer details:
http://blogs.msdn.com/junfeng/archive/2 ... abled.aspx
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby home3d2001 on Wed Oct 22, 2008 4:51 pm

Hi,

My questions might be stupid since I am new in Shader programming in Mental ray.

Alright, so basically I have the mental ray version 3.6.54.1 that comes with Andy Kopra book. My question is :

1- I found the public-shaders-3.5.7.10 under resources on your website and there is a shader.lib but where is the include folder?:).Are these all the libraries and headers I need to start compiling my my shaders in Visual c++ 2008( I have the full licence for VC 2008 so I don't want to use the express edition) .Do I need anything else?

Thank you again for your time and I appreciate if you help me out.

Hamed
Last edited by home3d2001 on Fri Oct 24, 2008 5:51 pm, edited 3 times in total.
home3d2001
 
Posts: 26
Joined: Fri Dec 28, 2007 1:57 am

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby home3d2001 on Thu Oct 23, 2008 6:52 am

Hi ,

Alright, I think I found the include folder in Mental ray that comes with Andy's book and I copied that in public-shaders-3.5.7.10.

Good news,I Hooked it up to Maya and got two sliders (X,y) where I can add simply two colors together:)

In include folder I have following files:

shader.h
mirelay.h
mia_material_api.h
mi_version.h
geoshader.h

and I have shader.lib in lib folder in public-shaders-3.5.7.10 which I downloaded from resources on lamrug website.

step2_3.jpg
step2_3.jpg (131.78 KiB) Viewed 1480 times


Thanks,


Hamed
home3d2001
 
Posts: 26
Joined: Fri Dec 28, 2007 1:57 am

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Sun Oct 26, 2008 8:51 am

Note to beware of mixing 3.5.7. with 3.6+. I don't understand why you are getting the 3.5.7.10 sources? Everything you need regarding shared libraries and include files should be included with the book. You could also look on the website www.writingshaders.com.

It should also be explained and if not, there is a sub-forum here to ask questions.
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby home3d2001 on Sun Oct 26, 2008 10:18 am

Hi,

Sorry,yes. I missed the folder nt-x86-vc8 in the CD comes with the book. :)

The only problem I have now is dealing with "miaux.h"

When I compile the summed_noise_scalar ,compiler gives me an error saying it can;t find the following headers

(Fetures.h, LETypes.h,OpenTypeTables.h)

What are these and where Can I find them?

Also,I already have io.h and unistd.h in my VC include file.

Thank you so much again for your time,

Hamed
home3d2001
 
Posts: 26
Joined: Fri Dec 28, 2007 1:57 am

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Sun Oct 26, 2008 11:09 am

I don't know where those are. miaux does not explicitly depend on those.

Do you have a command line shell window in your VC distribution, in which you could test the compilation?

In Express, there is one you can reach from the startup menus.
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby home3d2001 on Sun Oct 26, 2008 4:28 pm

Hi ,

I think I have the wrong unistd.h in my VS include folder. When I installed the MS VS 2008 on my machine there wasn't any unistd.h in the include folder.However,I could find IO.h there. I searched on google and found unistd.h and put it in my VS include folder.I found out later it was a wrong file ,and it is relying on other headers.

Could you please tell me where I can get the unistd.h or if someone have it , please post it so I can download it and use it.

Thanks so much in advance.

Hamed
home3d2001
 
Posts: 26
Joined: Fri Dec 28, 2007 1:57 am

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Sat Nov 01, 2008 7:09 am

I think I mention this above in step 2, but I'll repeat it here...

Copy io.h to unistd.h in the same directory.
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Sat Nov 01, 2008 7:13 am

Hi all,

I noticed that the SP1 version of Express 2008 takes a lot longer to download and install. Just thought I'd warn you.

Also, when loading the SDK for 64-bit you can choose to leave out some elements, and it should go faster.

I'm not sure, but it looks like maybe some of what was in the SDK was moved into the Express 2008 download, so that is why the shifting in time. But I noticed that overall, for a 64-bit system, the total download and install time was faster.
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby home3d2001 on Sat Nov 01, 2008 8:59 am

I think I mention this above in step 2, but I'll repeat it here...

Copy io.h to unistd.h in the same directory.



Thanks, but copy them from where? :D , I have the io.h by default in my VC 2008 include folder , but all I need is unistd.h :)
home3d2001
 
Posts: 26
Joined: Fri Dec 28, 2007 1:57 am

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby bart on Sun Nov 02, 2008 3:12 pm

make a copy of the io.h in that directory and rename it as unistd.h

The same contents, just different names.
bart
Site Admin
 
Posts: 1659
Joined: Sat Dec 18, 2004 9:34 am
Location: Marina Del Rey, California

Re: Compiling on Windows with MS VC Express 2008 and mr 3.6+

Postby home3d2001 on Sun Nov 02, 2008 6:32 pm

Hi Bart,

Perfect at least one of my problems is gone:D Thank you so much again.
home3d2001
 
Posts: 26
Joined: Fri Dec 28, 2007 1:57 am


Return to Getting Started

Who is online

Users browsing this forum: No registered users and 1 guest

cron