You are viewing the documentation for OpenSim 3.x. Are you looking for the latest OpenSim 4.0 Documentation?

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

In this first example, you will go step-by-step through the entire process of setting up your build folder using CMake, opening and viewing the C++ code in Visual Studio, compiling your first executable, running it and viewing the results in OpenSim.  The topics covered in this section include:

Prepare your Development Folder

Copy the <OpenSimInstallDir>/sdk/APIExamples/ExampleMain directory into a folder (work space) outside of the OpenSim installation so that future uninstalls and installs of OpenSim do not destroy your work. Any empty folder will do, for example, C:/OpenSimWorkspace/ would be easy to recognize. This will be referred to as <WorkSpace> below.

Running CMake

1) Go to Start -> CMake (cmake-gui)

2) For the field "Where is the source code": Browse to the correct folder where you stored your code such as <WorkSpace>/ExampleMain.

3) For the field "Where to build the binaries": Copy-paste the same folder into this field, but add a build folder. Eg. <WorkSpace>/ExampleMain/build (It's ok if you use all backslashes instead of all forward slashes)

4) Click Configure.

5) If the "build" directory doesn't exist yet, a message box will pop up asking if you want to create this directory. Click Yes.

6) Another dialog box will open. The drop-down menu provides a list of generators, which, for Visual Studio, is a combination of the Visual Studio version (e.g., "10 2010", "12 2013", "14 2015") and whether you want to build 32-bit or 64-bit ("Win64") executables with your CMake project. For OpenSim 3.3, you should select either "Visual Studio 12 2013" or "Visual Studio 12 2013 Win64" (in older versions of CMake, the options may appear as "Visual Studio 12" and "Visual Studio 12 Win64"). Which of the two you should choose depends on if OpenSim was built as 32-bit or 64-bit. If C:\OpenSim 3.3\sdk\buildinfo.txt contains "Win64", then choose "Visual Studio 12 2013 Win64"; otherwise, choose "Visual Studio 12 2013". Leave "Use default native compilers" selected in the option menu below the drop-down box. Click Finish.

7) One of the pink fields that shows up is called OPENSIM_INSTALL_DIR. Click to the right of where it says C:/OpenSim 3.x and make sure this is your <OpenSimInstallDir>.

8) Check that the TARGET is specified. This specifies the name of the Visual Studio Solution file and the app or .exe file that will be generated. In this case it is "exampleMain".

You can view the description of the CMake variables by hovering over the variable and waiting for a pop-up with info to appear.

9) Click Configure. The variable fields should no longer be pink, and the message window at the bottom of the CMake window should say "Configuring done".

10) Click Generate. The message window should now display:
Configuring done
Generating done

11) In CMake 3.8 and later, you can click the Open Project button to open the Visual Studio "solution" in Visual Studio.

12) Close CMake.

Running Visual Studio

1) If your CMake is older than 3.8, then you must open the Visual Studio solution manually. In Windows Explorer, navigate to the build directory you just created using CMake, e.g.,
<WorkSpace>/ExampleMain/build. Double-click on the solution file (.sln) that was just created, OpenSimTugOfWar.sln, which will launch Visual Studio with ExampleMain as a project.

2) The Solution Configuration (drop-down in the toolbar) should be Release. You can also choose RelWithDebInfo (Release with debug info), which will allow you to debug your code.

3) Open the TugOfWar1_CreateModel.cpp file, by browsing the libraries in your Solution Explorer.

4) Compile the .cpp file(s): right-click on ALL_BUILD and choose Build from the drop-down menu. In the bottom Output window you can see whether or not your file compiled correctly.

5) Run the program you just created, using one of two methods:

  • In Windows Explorer, navigate to the build directory and then to the Release directory. Open the executable that you just created: exampleMain.exe
  • Run the program from Visual Studio. In the Solution Explorer, right-click exampleMain, and select Set as StartUp Project. Then open the DEBUG menu and select Start Without Debugging. If you used RelWithDebInfo instead of Release and if you select Start With Debugging (from the DEBUG menu), you can pause the program at any line you want by adding a breakpoint. This you can do by clicking anywhere in the left grey column.

6) If you had issues running the program, it is likely because C:\OpenSim 3.3\bin is not on your Windows PATH; see the previous page for more information.

  • No labels