Creating a project from scratch

From Physics Simulation Wiki

(Difference between revisions)
Jump to: navigation, search
(Creating a project from scratch using XCode)
m (Added section for using Eclipse to create a project from Scratch.)
 
(15 intermediate revisions not shown)
Line 1: Line 1:
= Creating a project from scratch using Visual Studio (any version) =
= Creating a project from scratch using Visual Studio (any version) =
 +
Note: C++ is not included in Visual Studio 2015 by default and has to be manually selected during installation. [http://blogs.msdn.com/b/vcblog/archive/2015/07/24/setup-changes-in-visual-studio-2015-affecting-c-developers.aspx]
-
=== Download and install Bullet ===
+
=== Download Bullet ===
-
* Download the Bullet source code from http://code.google.com/p/bullet/downloads/list and unzip the archive somewhere, say c:\develop, so the root of Bullet is in c:\develop\bullet-2.76
+
* Download the Bullet source code from https://github.com/bulletphysics/bullet3/releases/latest and unpack the archive somewhere, say C:\Users\Dev\Desktop, so the root of Bullet is in C:\Users\Dev\Desktop\bullet3 (replace "Dev" with your username).
-
=== Download and install cmake ===
+
=== Download and install CMake ===
-
 
+
* The recommended way to start a new project from scratch is using CMake. Download CMake from http://cmake.org and install it.
-
* The recommended way to start a new project from scratch is using cmake. Download cmake from http://cmake.org and install it.
+
=== Run CMake-gui ===
=== Run CMake-gui ===
-
 
+
* Start CMake-gui.
-
* Start CMake-gui
+
<center>[[Image:start_cmake.PNG]]
<center>[[Image:start_cmake.PNG]]
</center>
</center>
-
* Choose the location where you unzipped the Bullet source code, and where you build the binaries for your own project and press Configure
+
* Choose the location where you unpacked the Bullet source code and where you build the binaries for your own project, then press Configure.
<center>[[Image:cmake_step0.PNG]]
<center>[[Image:cmake_step0.PNG]]
</center>
</center>
-
* Choose the compiler, such as Microsoft Visual Studio 2008
+
* Choose the compiler, such as Microsoft Visual Studio 2015.
<center>[[Image:cmake_step1.PNG]]
<center>[[Image:cmake_step1.PNG]]
</center>
</center>
-
* Review the settings and press Configure again
+
* Review the settings and press Configure again.
<center>[[Image:cmake_step2.PNG]]
<center>[[Image:cmake_step2.PNG]]
</center>
</center>
-
* Make sure the Run-time library is the same as your project (by default it is set to Run-time library DLL) and press Generate
+
* Make sure the [https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx run-time library] is the same as in your project. By default it is set to the multi-threaded, static version (/MT, USE_MSVC_RUNTIME_LIBRARY_DLL is unchecked). Then press Generate.
<center>[[Image:cmake_step3.PNG]]
<center>[[Image:cmake_step3.PNG]]
</center>
</center>
-
* Optionally, you could open the generated project solution (in our case C:\develop\tutorial\BulletBuild\BULLET_PHYSICS.sln) and build the library and demos, but this is not necessary
+
* Optionally, you could open the generated project solution (in our case C:\Users\Dev\Desktop\tutorial\build\BULLET_PHYSICS.sln) and build the library and demos, but this is not necessary.
== Create a new Visual Studio project ==
== Create a new Visual Studio project ==
-
 
+
* Now create your new project, say a Win32 Console Application in C:\Users\Dev\Desktop\tutorial called BulletTestApp, located in C:\Users\Dev\Desktop\tutorial
-
* Now create your new project, say a Win32 Console Application in c:\develop called BulletTestApp, located in c:\develop\BulletTestApp:
+
<center>[[Image:step1.PNG]]
<center>[[Image:step1.PNG]]
</center>
</center>
-
* Hit Finish
+
* Hit Finish.
<center>[[Image:step2.PNG]]
<center>[[Image:step2.PNG]]
</center>
</center>
-
* Just try to build it without any change
+
* Just try to build it without any change.
<center>[[Image:step3.PNG]]
<center>[[Image:step3.PNG]]
</center>
</center>
-
* Now add the generated projectfiles for the Bullet libraries, BulletCollision, BulletDynamics and LinearMath:
+
* Now add the generated project files for the Bullet libraries: BulletCollision, BulletDynamics and LinearMath.
<center>[[Image:step4.PNG]]
<center>[[Image:step4.PNG]]
</center>
</center>
-
* Browse to the folder where you selected CMake-gui to build the binaries, then select src/BulletCollision/BulletCollision.vcproj, and same for src/BulletDynamics/BulletDynamics.vcproj and src/LinearMath/LinearMath.vcproj:
+
* Browse to the folder where you selected CMake-gui to build the binaries, then select src/BulletCollision/BulletCollision.vxcproj, and same for src/BulletDynamics/BulletDynamics.vcxproj and src/LinearMath/LinearMath.vcxproj:
<center>[[Image:step5.PNG]]
<center>[[Image:step5.PNG]]
</center>
</center>
-
* Make sure to make your program dependent on the Bullet libraries, right click on your project, select 'Dependencies'
+
* For Visual Studio 2010 and above, add project references to Bullet libraries.
 +
 
 +
<center>[[Image:Project add reference.png]]
 +
</center>
 +
 
 +
 
 +
<center>[[Image:Project references.png]]
 +
</center>
 +
 
 +
When you get the error ''The project file has been moved renamed or not on your computer'', check the References for the newly added project. Removes references to 'ZERO_CHECK'.
 +
 
 +
* For Visual Studio 2008, you might instead need to enable the Link Library Dependencies setting for all projects, in the linker settings:
 +
 
 +
<center>[[Image:link_library_dependencies.png]]
 +
</center>
 +
 
 +
* Make sure to make your program dependent on the Bullet libraries. Go to Project Dependencies
<center>[[Image:step6.PNG]]
<center>[[Image:step6.PNG]]
Line 70: Line 84:
</center>
</center>
-
* Now set the header include path to the 'src' folder within Bullet source code, for example c:\develop\bullet-2.76\src in our case. Right click on your project, select 'Properties'
+
* Now set the header include path to the 'src' folder within Bullet source code, for example C:\Users\Dev\Desktop\bullet3\src in our case. Go to Project Properties.
<center>[[Image:step8.PNG]]
<center>[[Image:step8.PNG]]
</center>
</center>
-
* Goto C/C++, Additional Include Directories, and type/browse to the Bullet/src folder, in our case c:\develop\bullet-2.76\src
+
* Go to C/C++, Additional Include Directories. For all configurations, type/browse to the Bullet3/src folder, in our case C:\Users\Dev\Desktop\bullet3\src.
<center>[[Image:step9.PNG]]
<center>[[Image:step9.PNG]]
</center>
</center>
-
* Repeat those steps for all configurations (Debug, Release etc), and start programming
+
* If USE_MSVC_RUNTIME_LIBRARY_DLL was not selected above, the project must use the non-DLL runtime library - Multi-threaded (/MT). Otherwise, use Multi-threaded DLL(/MD). For debug configurations, use the debug version of the runtime library.
-
<center>[[Image:step10.PNG]]
+
<center>[[Image:cpp_runtime.png]]
</center>
</center>
-
* You might need to enable the Link Library Dependencies setting for all projects, in the linker settings:
+
* Start programming.
-
<center>[[Image:link_library_dependencies.png]]
+
<center>[[Image:step10.PNG]]
</center>
</center>
Line 99: Line 113:
* Add a new C++ file (e.g. "main.cpp") to your project and copy the code from the [[Hello World]] page into it and save it.
* Add a new C++ file (e.g. "main.cpp") to your project and copy the code from the [[Hello World]] page into it and save it.
* Open the properties of your project (in the Solution Explorer right-click the project name and select Properties, or in the Property Manager double-click Debug|Win32):
* Open the properties of your project (in the Solution Explorer right-click the project name and select Properties, or in the Property Manager double-click Debug|Win32):
-
* In Configuration Properties > C/C++ > General > Additional Include Directories add: <source lang=dos>C:\bullet-2.75\src</source>
+
* In Configuration Properties > C/C++ > General > Additional Include Directories add:
 +
<source lang=html>C:\bullet-2.75\src</source>
* Recursively add all .cpp files from the Bullet/src folder to your project
* Recursively add all .cpp files from the Bullet/src folder to your project
* Build and debug your project.
* Build and debug your project.
 +
 +
 +
= Creating a project from scratch using Eclipse (Linux) =
 +
 +
Work in progress.
= Creating a project from scratch using XCode  =
= Creating a project from scratch using XCode  =
Line 135: Line 155:
</center>
</center>
-
* If you are having trouble with the following build errors:
+
* Update 12/17/2010: If you are having trouble with the following build errors:
   "btTypedConstraint::serialize(void*, btSerializer*) const", referenced from:
   "btTypedConstraint::serialize(void*, btSerializer*) const", referenced from:
Line 141: Line 161:
   "btAlignedFreeInternal(void*)", referenced from:
   "btAlignedFreeInternal(void*)", referenced from:
-
then you have to include the bullet frameworks in your Xcode project. Make sure they are built and installed like this (This is without Xcode, maybe there is some way to make them in Xcode too, I don't know):
+
then you have to include the Bullet frameworks in your Xcode project. Make sure they are built and installed like this (This is without Xcode, maybe there is some way to make them in Xcode too, I don't know):
     cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON \
     cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON \
Line 150: Line 170:
     sudo make install
     sudo make install
-
(I essentially got that from [[http://bulletphysics.org/mediawiki-1.5.8/index.php/Installation here]].)
+
This will put the Bullet frameworks in /Library/Frameworks. Navigate there in the finder and then drag the frameworks into your Xcode project. You need at least LinearMath.framework and BulletDynamics.framework. (Those two will fix the above linking errors.) But you probably also want BulletCollision.framework and maybe others.
-
This will put the Bullet libraries in /Library/Frameworks. Navigate there in the finder and then drag the frameworks into your Xcode project. You need at least LinearMath.framework and BulletDynamics.framework. (Those two will fix the above linking errors.) But you probably also want BulletCollision.framework and maybe others.
+
If you have set up the frameworks like this, you don't have to change the header search path as above. Instead you can put this include line and Xcode will find the headers inside the framework:
 +
  #include <BulletDynamics/btBulletDynamicsCommon.h>
* From here, continue to the [[Hello World]] tutorial.
* From here, continue to the [[Hello World]] tutorial.
 +
 +
= Unix, Linux, MinGW etc =
 +
 +
Follow the generic make recipe from the [[Installation|installation]] guide making sure the .a files are built.  From there, when creating a Makefile, in the gcc arguments, make sure you add in a -I '''bullet_dir''' for the headers and also add in '''libBulletDynamics.a''', '''libBulletCollision.a''' and '''libLinearMath.a''' or whatever you're using.
 +
 +
For example (assuming the src dir is in the folder bullet):
 +
 +
gcc myprogram.cpp -lGL -lGLU -I ./bullet/ ./bullet/BulletDynamics/libBulletDynamics.a ./bullet/BulletCollision/libBulletCollision.a ./bullet/LinearMath/libLinearMath.a
 +
 +
= Link order for libraries =
 +
Note that many compilers the link order matters, so make sure to use the following order of libraries:
 +
 +
* BulletMultiThreaded (optional)
 +
* MiniCL (optional)
 +
* BulletWorldImporter (optional)
 +
* BulletSoftBody (optional)
 +
* BulletDynamics
 +
* BulletCollision
 +
* LinearMath
 +
 +
[[Category:Getting started]]

Current revision as of 19:14, 25 October 2016

Contents

Creating a project from scratch using Visual Studio (any version)

Note: C++ is not included in Visual Studio 2015 by default and has to be manually selected during installation. [1]

Download Bullet

Download and install CMake

  • The recommended way to start a new project from scratch is using CMake. Download CMake from http://cmake.org and install it.

Run CMake-gui

  • Start CMake-gui.
Image:start_cmake.PNG
  • Choose the location where you unpacked the Bullet source code and where you build the binaries for your own project, then press Configure.
Image:cmake_step0.PNG
  • Choose the compiler, such as Microsoft Visual Studio 2015.
Image:cmake_step1.PNG
  • Review the settings and press Configure again.
Image:cmake_step2.PNG
  • Make sure the run-time library is the same as in your project. By default it is set to the multi-threaded, static version (/MT, USE_MSVC_RUNTIME_LIBRARY_DLL is unchecked). Then press Generate.
Image:cmake_step3.PNG
  • Optionally, you could open the generated project solution (in our case C:\Users\Dev\Desktop\tutorial\build\BULLET_PHYSICS.sln) and build the library and demos, but this is not necessary.

Create a new Visual Studio project

  • Now create your new project, say a Win32 Console Application in C:\Users\Dev\Desktop\tutorial called BulletTestApp, located in C:\Users\Dev\Desktop\tutorial
Image:step1.PNG
  • Hit Finish.
Image:step2.PNG
  • Just try to build it without any change.
Image:step3.PNG
  • Now add the generated project files for the Bullet libraries: BulletCollision, BulletDynamics and LinearMath.
Image:step4.PNG
  • Browse to the folder where you selected CMake-gui to build the binaries, then select src/BulletCollision/BulletCollision.vxcproj, and same for src/BulletDynamics/BulletDynamics.vcxproj and src/LinearMath/LinearMath.vcxproj:
Image:step5.PNG
  • For Visual Studio 2010 and above, add project references to Bullet libraries.
Image:Project add reference.png


Image:Project references.png

When you get the error The project file has been moved renamed or not on your computer, check the References for the newly added project. Removes references to 'ZERO_CHECK'.

  • For Visual Studio 2008, you might instead need to enable the Link Library Dependencies setting for all projects, in the linker settings:
Image:link_library_dependencies.png
  • Make sure to make your program dependent on the Bullet libraries. Go to Project Dependencies
Image:step6.PNG
  • and select the Bullet libraries:
Image:step7.PNG
  • Now set the header include path to the 'src' folder within Bullet source code, for example C:\Users\Dev\Desktop\bullet3\src in our case. Go to Project Properties.
Image:step8.PNG
  • Go to C/C++, Additional Include Directories. For all configurations, type/browse to the Bullet3/src folder, in our case C:\Users\Dev\Desktop\bullet3\src.
Image:step9.PNG
  • If USE_MSVC_RUNTIME_LIBRARY_DLL was not selected above, the project must use the non-DLL runtime library - Multi-threaded (/MT). Otherwise, use Multi-threaded DLL(/MD). For debug configurations, use the debug version of the runtime library.
Image:cpp_runtime.png
  • Start programming.
Image:step10.PNG
  • From here, you could try out the Hello World tutorial


Alternative, manual method

If you do not want to use cmake, here is another simple method. Assuming you have unzipped Bullet in C:\bullet-2.75\, adjust all pathnames if necessary:

  • Create a new, empty C++ project (File > New > Project: Choose Project types > Visual C++ > General > Empty Project)
  • Add a new C++ file (e.g. "main.cpp") to your project and copy the code from the Hello World page into it and save it.
  • Open the properties of your project (in the Solution Explorer right-click the project name and select Properties, or in the Property Manager double-click Debug|Win32):
  • In Configuration Properties > C/C++ > General > Additional Include Directories add:

C:\bullet-2.75\src
  • Recursively add all .cpp files from the Bullet/src folder to your project
  • Build and debug your project.


Creating a project from scratch using Eclipse (Linux)

Work in progress.

Creating a project from scratch using XCode

Assume we downloaded bullet-2.x.tgz and unzipped it into a folder /Users/name/develop, we will have for example: /Users/name/develop/bullet-2.76

  • Create a new C++ console application, using XCode:
Image:newxcodeproject.png
  • put it in next to bullet-2.x, in the develop folder:

Image:developfolder.png

  • Open the main.cpp file and add #include "btBulletDynamicsCommon.h":

Image:addcommoninclude.png

  • Edit the project settings for All Configurations

Image:editxcodeprojectsettings.png

  • Add the bullet-2.x/src folder:

Image:addbulletsrcinclude.png

Image:addbulletsrcinclude1.png

  • Now build the project:

Image:buildxcode.png

  • Update 12/17/2010: If you are having trouble with the following build errors:
 "btTypedConstraint::serialize(void*, btSerializer*) const", referenced from:
 "btAlignedFreeInternal(void*)", referenced from:

then you have to include the Bullet frameworks in your Xcode project. Make sure they are built and installed like this (This is without Xcode, maybe there is some way to make them in Xcode too, I don't know):

   cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON \
    -DFRAMEWORK=ON  -DCMAKE_OSX_ARCHITECTURES='i386;x86_64' \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/Library/Frameworks \
    -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks -DBUILD_DEMOS:BOOL=OFF
   make -j4
   sudo make install

This will put the Bullet frameworks in /Library/Frameworks. Navigate there in the finder and then drag the frameworks into your Xcode project. You need at least LinearMath.framework and BulletDynamics.framework. (Those two will fix the above linking errors.) But you probably also want BulletCollision.framework and maybe others.

If you have set up the frameworks like this, you don't have to change the header search path as above. Instead you can put this include line and Xcode will find the headers inside the framework:

  #include <BulletDynamics/btBulletDynamicsCommon.h>

Unix, Linux, MinGW etc

Follow the generic make recipe from the installation guide making sure the .a files are built. From there, when creating a Makefile, in the gcc arguments, make sure you add in a -I bullet_dir for the headers and also add in libBulletDynamics.a, libBulletCollision.a and libLinearMath.a or whatever you're using.

For example (assuming the src dir is in the folder bullet):

gcc myprogram.cpp -lGL -lGLU -I ./bullet/ ./bullet/BulletDynamics/libBulletDynamics.a ./bullet/BulletCollision/libBulletCollision.a ./bullet/LinearMath/libLinearMath.a

Link order for libraries

Note that many compilers the link order matters, so make sure to use the following order of libraries:

  • BulletMultiThreaded (optional)
  • MiniCL (optional)
  • BulletWorldImporter (optional)
  • BulletSoftBody (optional)
  • BulletDynamics
  • BulletCollision
  • LinearMath
Personal tools