Skip to end of metadata
Go to start of metadata

The easiest way to use Ice with Visual Studio is to use our Visual Studio Add-In. The add-in automates the chores of adding Slice files to a project, generating the code, tracking dependencies among Slice files, and other things. The instructions that follow describe how to create Visual Studio projects from scratch, without the assistance of the add-in.

On this page:

Configure Directory Paths

To build Ice for C++ applications with Visual Studio, you must configure the C++ directory paths. On the Tools menu, choose Options, and then select Projects and Solutions. You can change the directories that Visual Studio searches in the VC++ Directories category. (You need to perform this step only once.)

You need to add three directories to the configuration. In the Show directories for drop-down, select:

  • Executable files
    Add the Ice bin directory to the list of directories. For example, if you have installed Ice in C:\Ice-3.3.1-VC90, add C:\Ice-3.3.1-VC90\bin to the list.
  • Header files
    Add the Ice include directory to the list of directories. For example, if you have installed Ice in C:\Ice-3.3.1-VC90, add C:\Ice-3.3.1-VC90\include to the list.
  • Library files
    Add the Ice lib directory to the list of directories. For example, if you have installed Ice in C:\Ice-3.3.1-VC90, add C:\Ice-3.3.1-VC90\lib to the list.

If you want to create 64-bit binaries, select x64 as the platform and set the directory for executables and libraries to bin\x64 and lib\x64, respectively; the include directory is the same as for 32-bit builds (include).

Create a C++ Project

On the File menu, select New, and then choose New Project. The project template will normally be Win32 Console Application. However, you are free to choose a different project template for your application.

In the Application Settings dialog, change the settings to suit your needs. You can start with an empty project or, if you prefer, use precompiled headers.

Add Slice Files and Custom Build Steps to Project

In your new project, right-click Resource Files, and then select Add Existing Item. Select the Slice file you want to add to the project. Next, right-click on the newly-added file and select Properties. Set Configuration to All Configurations and provide the command to run the Slice compiler (slice2cpp) and set the output file names produced when you compile the Slice file. Note the use of macros to specify the input and output file names.

If your Slice file includes any of the Slice files that ship with Ice, you must add the slice directory with the -I option to the list of directories that are searched for included files. For example, if Ice is installed in C:\Ice-3.3.1-VC90, add -IC:\Ice-3.3.1-VC90\slice to the command line.

If your Slice files include other Slice files, you must inform Visual Studio of the dependency. For example, if Demo.ice includes Included.ice, you must add Included.ice to the Additional Dependencies item for Demo.ice; otherwise, Visual Studio will not recompile Demo.ice when you make a change to Included.ice. Note that you need to specify the directory in which Included.ice is located with the -I option for the custom build step for Demo.ice:

Add C++ Source and Header Files to Project

Once you have added your Slice files to the project and specified the custom build steps, right-click each Slice file and select Compile to generate the header and source files. You can now add the generated files to their respective project folders:

You also need to add the header and source files used by your application. In this case, we added a single source file Client.cpp. Note that you must add . (the current directory) to the include path of Client.cpp for both release and debug configurations because that is where slice2cpp places the generated files, and Client.cpp includes Demo.h.

Set Project Properties

You must ensure that the project property settings when you compile match those that were used to compile the Ice libraries. In particular, you must set Enable C++ Exceptions to Yes (/EHsc). For Runtime Library, select Multi-threaded Debug DLL (/MDd) for a debug build, and Multi-threaded DLL (/MD) for a release build. (The screen shot below shows the setting for a debug build.)

For the Language settings, ensure that Enable Run-Time Type Info is set to Yes.

Your project must link (at a minimum) with the IceUtil and Ice libraries. If you use other parts of Ice, such as Glacier2 or Freeze, you must link with the libraries for these as well. For a debug build, the libraries have d-suffix, so the libraries are iceutild.lib and iced.lib. for a release build, the d-suffix is missing, so the libraries are iceutil.lib and ice.lib.

Make sure that debug and release builds link with the correct library; otherwise, even though things may compile, the program will crash at run time (For more details, see the FAQ, "Why does my application work fine in release mode but crash in debug mode?").

For 64-bit builds, use Configuration Manager in the project properties to add x64 as a new platform and then set x64 as the active configuration in the project properties.

See Also
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.