Using CPLEX with Microsoft Visual C++ This file describes how to use Microsoft Visual Studio to build and run the C and C++ examples delivered with CPLEX (see dotnet.html for the C# and VB examples). create a C or C++ project and link the target with CPLEX. CPLEX Installation Folder Throughout this document, the CPLEX installation folder is referred to as <CPLEXDIR>, and the Concert Technology installation folder is referred to as <CONCERTDIR>. For example, if CPLEX has been installed in the folder C\ILOG\CPLEX111 (the default location), references to <CPLEXDIR>\include represent C\ILOG\CPLEX111\include. The default for Concert Technology is C\ILOG\Concert26. Libraries The ILOG Concert Technology libraries are delivered in two static formats for Visual Studio 2005 (x86_.net2005_8.0), so that a static executable can be linked with libcmt.lib or msvcrt.lib. These two formats use the standard template library (STL) and are compiled using the namespace std. Similarly, for Visual Studio 2008 (x86_windows_vs2008 or x64_windows_2008), the same two formats are supported, multi threaded, and multithreaded DLL. The ILOG CPLEX library is delivered as a DLL so that it may be used with any of the library formats, but there is an associated library file of each format with which to link. Library Locations Visual Studio 2005 libraries can be found in the following directories multi threaded STL <CPLEXDIR>\lib\x86_.net2005_8.0\stat_mta\ilocplex.lib <CPLEXDIR>\lib\x86_.net2005_8.0\stat_mta\cplex111.lib <CONCERTDIR>\lib\x86_.net2005_8.0\stat_mta\concert.lib <CPLEXDIR>\lib\x64_.net2005_8.0\stat_mta\ilocplex.lib <CPLEXDIR>\lib\x64_.net2005_8.0\stat_mta\cplex111.lib <CONCERTDIR>\lib\x64_.net2005_8.0\stat_mta\concert.lib These libraries must be linked with libcmt.lib multi threaded DLL STL <CPLEXDIR>\lib\x86_.net2005_8.0\stat_mda\ilocplex.lib <CPLEXDIR>\lib\x86_.net2005_8.0\stat_mda\cplex111.lib file///c/users/edalkiran/dropbox/courses/advancedip/papers/cplex/c_cpp.html 1/5
<CONCERTDIR>\lib\x86_.net2005_8.0\stat_mda\concert.lib <CPLEXDIR>\lib\x64_.net2005_8.0\stat_mda\ilocplex.lib <CPLEXDIR>\lib\x64_.net2005_8.0\stat_mda\cplex111.lib <CONCERTDIR>\lib\x64_.net2005_8.0\stat_mda\concert.lib These libraries must be linked with msvcrt.lib Visual Studio 2008 libraries can be found in the following directories multi threaded STL multi threaded DLL STL <CPLEXDIR>\lib\x86_windows_vs2008\stat_mta\ilocplex.lib <CPLEXDIR>\lib\x86_windows_vs2008\stat_mta\cplex111.lib <CONCERTDIR>\lib\x86_windows_vs2008\stat_mta\concert.lib <CPLEXDIR>\lib\x64_windows_vs2008\stat_mta\ilocplex.lib <CPLEXDIR>\lib\x64_windows_vs2008\stat_mta\cplex111.lib <CONCERTDIR>\lib\x64_windows_vs2008\stat_mta\concert.lib These libraries must be linked with libcmt.lib <CPLEXDIR>\lib\x86_windows_vs2008\stat_mda\ilocplex.lib <CPLEXDIR>\lib\x86_windows_vs2008\stat_mda\cplex111.lib <CONCERTDIR>\lib\x86_windows_vs2008\stat_mda\concert.lib <CPLEXDIR>\lib\x64_windows_vs2008\stat_mda\ilocplex.lib <CPLEXDIR>\lib\x64_windows_vs2008\stat_mda\cplex111.lib <CONCERTDIR>\lib\x64_windows_vs2008\stat_mda\concert.lib These libraries must be linked with msvcrt.lib Building and Running CPLEX Examples The C and C++ CPLEX examples have all been gathered in one project for each type of static format (sta, mta, and mda). The instructions below use the mta format for the Visual Studio 2005 environment, but the same instructions apply when using the project file for another format or with Visual Studio 2008. The related file for the mta format is <CPLEXDIR>\examples\x86_.net2005_8.0\stat_mta\examples.sln. Be aware that the order of the instructions below is important. 1. Start Microsoft Visual Studio 2005. 2. From the File menu, choose Open Project/Solution. The Open Project dialog box appears. If the default selection in the Files Of Type drop down list is Project Files, change it to Solution Files. Select the folder <CPLEXDIR>\examples\x86_.net2005_8.0\stat_mta. Select the examples file and click Open. 3. To build only one example (for instance, blend) Select the blend project in the Solution Explorer window. file///c/users/edalkiran/dropbox/courses/advancedip/papers/cplex/c_cpp.html 2/5
From the Build menu, choose Build blend. Wait for the completion of the building process. 4. To build all of the examples From the Build menu, choose Build Solution Wait for the completion of the building process. 5. To run an example (for instance, blend) Open a command prompt window by running the Visual Studio 2005 Command Prompt. In the window Visual Studio 2005 Command prompt Type set path=%path%;<cplexdir>\bin\x86_win32 so that cplex111.dll is on the path. Type <CPLEXDIR>\examples\x86_.net2005_8.0\stat_mta\blend. The result is then displayed. Building Your Own Project which Links with CPLEX Note The information below applies to the Visual C++ 2005 multi threaded STL library. If you use another version of the library, set the Runtime Library option to match the library version. If you use Visual Studio 2008, the instructions below should apply, except that x86_.net2005_8.0 should be replaced with x86_windows_vs2008 whenever a path name is specified. Let's assume that you want to build a target named test.exe and have a source file named test.cpp which uses ILOG Concert Technology or test.c which uses the C API of the CPLEX Callable Library; a folder where this file is located and which, for the sake of simplicity, we'll refer to as <MYAPPDIR>. One way to achieve that is to create a project named test.vcproj as described here. Be aware that the order of instructions is important. 1. Start Microsoft Visual Studio 2005. 2. The first step is to build the test.sln solution. From the File menu, select New >, and then Project... The New Project dialog box appears. In the Project Types pane, select Visual C++ Projects. In the Templates pane, select the Win32 Project icon. Fill in the project name (test). If necessary, correct the location of the project (to <MYAPPDIR>) Click OK When the Win32 Application Wizard appears... file///c/users/edalkiran/dropbox/courses/advancedip/papers/cplex/c_cpp.html 3/5
Click on Application Settings. Select Console Application as Application type. Make sure that Empty project is checked in Additional Options. Click Finish. This creates a solution, test, with a single project, test. You can see the contents of the solution by selecting Solution Explorer in the View menu. 3. Now you must add your source file to the project. From the Project menu, choose Add Existing Item... Move to the folder <MYAPPDIR> and select test.cpp or test.c. Click Open. 4. Next, you have to set some options so that the project knows where to find the ILOG CPLEX/Concert include files and the ILOG CPLEX/Concert libraries. From the Project menu, choose Properties. The test Property Pages dialog box appears. In the Configuration drop down list, select Release. Select C/C++ in the Configuration Properties tree. Select General In the Additional Include Directories field, add the directories <CPLEXDIR>\include. <CONCERTDIR>\include. For Debug Information Format, choose Disabled (/Zd). Choose No for Detect 64 bit Portability Issues. Select Preprocessor Add IL_STD to the Preprocessor Definitions field. This defines the macro IL_STD which is needed to use the STL. Select Code Generation Set Runtime Library to Multi threaded (/MT). Select Linker in the Configuration Properties tree. Select Input and then select Additional Dependencies. Add the files wsock32.lib <CPLEXDIR>\lib\x86_.net2005_8.0\stat_mta\cplex111.lib <CPLEXDIR>\lib\x86_.net2005_8.0\stat_mta\ilocplex.lib <CONCERTDIR>\lib\x86_.net2005_8.0\stat_mta\concert.lib The latter two are only necessary if you are using ILOG Concert Technology. Click OK to close the test Property Pages dialog box. 5. Next, you have to set the default project configuration. From the Build menu, select Configuration Manager... Select Release in the Active Solution Configuration drop down list. file///c/users/edalkiran/dropbox/courses/advancedip/papers/cplex/c_cpp.html 4/5
Click Close. 6. Finally, to build the project, from the Build menu, select Build Solution After completion of the compiling and linking process, the target is created. The full path of the test.exe is <MYAPPDIR>\test\Release\test.exe. Remark From the Concert point of view, the only difference between the Win32 Release and Win32 Debug targets is the NDEBUG macro is defined for the Win32 Release target. the NDEBUG macro is not defined for the Win32 Debug target. This is why we have suggested using Release in the test.sln example, even though it is not the default proposed by Visual C++.NET. Refer to the Visual C++ Reference Manual for full information on Release and Debug configurations. The interaction of the NDEBUG macro and the Concert inline member functions is documented in the Concepts section of the ILOG CPLEX C++ API Reference Manual. file///c/users/edalkiran/dropbox/courses/advancedip/papers/cplex/c_cpp.html 5/5