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

Step-by-Step Example

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 up entitled "cmake-gui" - in the drop-down menu, select the version of Visual Studio you will use to compile the ExampleMain project, e.g. Visual Studio 10. Leave "Use default native compilers" selected in the option menu below the drop-down box. Click Finish.

7) One pink field will show up called OPENSIM_INSTALL_DIR. Click to the right of where it says C:/OpenSim2.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 "TugOfWar_Complete".

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 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) Close CMake.

Running Visual Studio

1) In Windows Explorer, navigate to the build directory you just created using CMake, eg.
<WorkSpace>/ExampleMain/build

2) Double-click on the solution file (.sln) that was just created, OpenSimTugOfWar.sln, which will launch Visual C++ with ExampleMain as a project.

3) Change the Solution Configuration from Debug (default) to Release. You can also choose RelWithDebInf (Release with debug info), which will allow you to debug your code.

4) Open the TugOfWar_Complete.cpp file, by browsing the libraries in your Solution Explorer on the left. Read through the .cpp file and see if you can understand, with help of the comments, what it does.

5) 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.

6) 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: StartUpExample.exe
  • Run the program from VS, by clicking the green arrow button. If you used RelWithDebInfo 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.

OpenSim is supported by the Mobilize Center , an NIH Biomedical Technology Resource Center (grant P41 EB027060); the Restore Center , an NIH-funded Medical Rehabilitation Research Resource Network Center (grant P2C HD101913); and the Wu Tsai Human Performance Alliance through the Joe and Clara Tsai Foundation. See the People page for a list of the many people who have contributed to the OpenSim project over the years. ©2010-2024 OpenSim. All rights reserved.