1

I've been working on some kind of "game engine" in c++ and every time I launch my "engine" it's compiling all files again which takes not too much time right now, but I think it will when I'll be adding new files. I am using vs code and my "args" in tasks.json currently look like this:

    "args": [
            "-g",
            "include\\implementation\\engine\\my_time.cpp",
            "include\\implementation\\engine\\texture_render.cpp",
            "include\\implementation\\engine\\game.cpp",
            "include\\implementation\\engine\\additional_draw.cpp",
            "include\\implementation\\engine\\vector2.cpp",
            "include\\implementation\\engine\\color.cpp",
            "include\\implementation\\engine\\my_math.cpp",
            "include\\implementation\\game\\planet.cpp",
            "src\\main.cpp",
            "-o",
            "build\\game.exe",
            "-IC:/SDL2-2.0.14/i686-w64-mingw32/include",
            "-LC:/SDL2-2.0.14/i686-w64-mingw32/lib",
            "-lmingw32",
            "-lSDL2main",
            "-lSDL2",
            "-lSDL2_ttf",
            "-mwindows"
        ]

So my question is that, is there any way to avoid all that recompilation?

ShirChoi
  • 11
  • 1
  • You need to use a build system to accomplish this (easily at least). CMake is pretty good, but quite hard to get going. Meson is another option. My personal favorite is [DDS](https://dds.pizza/), but it hasn't reached 1.0 yet and is still lacking major features. – Justin Jul 16 '21 at 15:56
  • Incremental recompilation is typically taken care of by a build system. Typical tools there are Make and Ninja, which require you to write the instructions yourself. People often reach for cross-platform CMake to *generate* build systems appropriate to the platform used. – Botje Jul 16 '21 at 15:58
  • Does this answer your question? [C++ Build Systems - What to use?](https://stackoverflow.com/questions/12017580/c-build-systems-what-to-use) – Botje Jul 16 '21 at 15:58
  • [(Tutorial) Learn Makefiles](https://makefiletutorial.com/) – Galik Jul 16 '21 at 16:18
  • For development work, use a *makefile*. The *make* utility will only build the files whose dependencies were changed. When deploying your project, you'll want to build the entire project. Is rebuilding taking too long for your tastes? Search the internet for "overnight software building", to see if you are impatient or not. – Thomas Matthews Jul 16 '21 at 17:18
  • As others have said, you need a build system, like make or ninja. The reason is that by listing every .cpp file in your program to compiler, you are literally commanding the compiler to compile all of those .cpp files every time, whether or not they have changed. – Matthew Curry Jul 16 '21 at 17:30

0 Answers0