Added section on separate compilation to Readme
This commit is contained in:
parent
1bd9c7e4ef
commit
cb05e2489e
28
README.md
28
README.md
@ -1,5 +1,5 @@
|
||||
# Raylib C++ Starter
|
||||
The Raylib C++ Starter kit is a template project that provides a simple starter template for the [raylib](https://github.com/raysan5/raylib) game tools library incorporating the [raylib-cpp](https://github.com/robloach/raylib-cpp) C++ bindings and using [Make](https://www.gnu.org/software/make/) for building. The starter kit can automatcially clone down raylib and the bindings, compile them, and setup the project for conditional compilation using a static library.
|
||||
The Raylib C++ Starter kit is a template project that provides a simple starter template for the [raylib](https://github.com/raysan5/raylib) game tools library incorporating the [raylib-cpp](https://github.com/robloach/raylib-cpp) C++ bindings and using [Make](https://www.gnu.org/software/make/) for building. The starter kit can automatcially clone down raylib and the bindings, compile them, and setup the project for separate compilation using a static library.
|
||||
|
||||
> Why static linking?
|
||||
|
||||
@ -50,6 +50,32 @@ Now that you have the project setup and compiling on your system, it's time to s
|
||||
|
||||
Once you're up and running, we first of all recommend that all your code for the game should go into the `/src` directory, which is automatically included in the compile process when you run Make. The default entry point for the program is `/src/main.cpp` (which is pretty standard). If you wish to change the program entry point, add more libraries, or really anything about your project, all build instructions are specified in the [`Makefile`](Makefile) - no smoke and mirrors!
|
||||
|
||||
### Making Use of Separate Compilation
|
||||
When building compiled applications from scratch, *each* source file needs to be compiled into an object file in order for them all to be linked together as a full program. This can become rather time-consuming and inefficient as your codebase expands to use tens or even hundreds of files that recompile each time you build. Fortunately, with a few clever rules in our [`Makefile`](Makefile), we can be sure to only have to recompile files affected by our changes.
|
||||
|
||||
By using the following Make commands instead of the default target, we can skip the cleanup step, and only recompile files that changed:
|
||||
|
||||
#### macOS & Linux
|
||||
|
||||
```console
|
||||
$ make bin/app; make execute
|
||||
```
|
||||
|
||||
#### Windows
|
||||
|
||||
```console
|
||||
> mingw32-make bin/app && mingw32-make execute
|
||||
```
|
||||
|
||||
Using this method can save you a huge amount of time compiling *(in reality, just a few seconds)* each time you make a small change to your code! If you want to know more about how it works, you should have a read through [the docs entry explaining the Makefile](docs/MakefileExplanation.md).
|
||||
|
||||
While separate compilation works quite well in most scenarios, it's not magic, and there are a few caveats to take note of here:
|
||||
|
||||
1. Changing `.h` files will often result in longer compile times by causing all files that include them to recompile
|
||||
2. Constant changes to files included by many others in your program (like a base-class) will also cause all of those dependent to recompile
|
||||
3. Including widely-scoped files (like the whole of `raylib-cpp.hpp`) will add all of its own includes as dependent and increase the build time
|
||||
4. Placing includes in `.h` files instead of forward-declarations will also increase recursive includes and therefore the build time
|
||||
|
||||
### Specifying a Non-Default Compiler
|
||||
If you want to use a compiler for your platform that isn't the default for your system (or potentially you would like to explicitly state it), you can make use of the system-implicit `CXX` variable like so:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user