Linux Setup
System setup
These steps need to be done only once on a given computer.You system will need the following elements:
- - A C++ compiler (gcc or clang), and compilation tools including pkg-config
- - CMake
- - GLFW Library
# Make sure that your apt deposit is updated [optional] sudo apt-get update # Basic development tools (g++, make, etc) sudo apt-get install build-essential pkg-config # Install CMake tool sudo apt-get install cmake # Install GLFW library sudo apt-get install libglfw3-dev
First compilation
The following instructions need to be done in full once per projet, or/and when a given project is moved from one machine to another.Open a command line in the "root" directory corresponding to a scene.
- For instance examples/example_compilation/
The "root" directory of a scene always contain a premade Makefile and a CMakeLists.txt. You can compile and execute the project using either of them on command line.
Method 1: If you use the provided Makefile
make # You can also type make -j$(nproc) for faster compilation in parallel # Or make -j 4 (replace 4 with any number of threads you want) ./example_compilation # adapt the name of the executable depending on the scene
Note:
- - If this method works, it is the simplest one on command line.
- - Make is a standard Unix command allowing to automatize some calls efficiently. The Makefile is the file that parameterizes which operations should be done when calling the command "make". In our case, it calls the C++ compiler (g++) on all the sources files.
Method 2: If you use the CMakeLists.txt
# Create a separated directory (avoids "polluting" the root directory) mkdir build # Go to the build/ directory cd build # Run CMake cmake .. # A file Makefile should be generated # Compile make # Make sure the compilation succeed, an executable should be created (ex. example_compilation) # You can also type make -j$(nproc) for faster compilation in parallel # Or make -j 4 (replace 4 with any number of threads you want) # Run the executable (adapt the name to your current scene) ./example_compilation
- - This method requires more steps than using the provided Makefile, but may work on more systems.
- - CMake is a high level tool to handle compilation processes for possibly large project. CMake does not compile itself the code, but generate intermediate files such as Makefile on Unix, or Visual Studio projects on Windows. CMake can also be used by IDE to load projects.
- - The execution of CMake is parameterized by the file CMakeLists.txt.
Re-compiling after code modification
When the C++ code is modified, a new executable must be compiled again. This compilation simply consists in calling make again (or make -j[N]).make # recompile only what is necessary ./example_compilation # run the new executable
Notes:
- - To clear the temporary files generated during the compilation you can type make clean.
- - When calling several times "make" on the same project, only the files that need to be recompiled (the one that have been modified) are processed. This allows to save time compare to a complete compilation of all the source files.
- - When using CMake, the build/ directory only contains temporary files. This directory can be removed safely and re-generated on demand. This build/ directory is dependant of the machine, and should not be uploaded on a shared repository using git for instance.
IDE for code edition
Beyond the simple compilation and execution of the project, you are highly encouraged to use a complete IDE (Integrated Development Environment) to edit C++ code. Compared to a simple text editor, an IDE will help you to use efficiently a library (such as CGP) in providing auto-completion (for functions/class names, arguments, etc) to naviguate quickly through the files, as well as proposing debug tools.You may use VS Code with C++ plugins. Make sure to load a project in opening a folder ("File" "Open Folder) the root directory, and not simply opening a single file. VS Code is a versatile tool usefull for multiple language, but may require some setup to recognize C++ project.
Another good IDE for C++ is QtCreator. QtCreator has the advantage to be able to be specialized for C++ and doesn't require any tuning or plugins to work.
QtCreator can be installed on Ubuntu using these instructions
sudo apt-get install qtcreator