Here's the problem: I want to split up my program primarily for compile time and secondarily for ease of writing the program. I am using a "compile.bat" program I wrote myself containing
g++ -o prog.exe main.cpp -lmingw32 -lSDLmain -lSDL
pause >nul
in order to do the compiling (MinGW is being used for the compilation as stated in the title) but the problem is, although I can easily add more files for compiling in the list after "prog.exe" (it's a one-file list for now so it's not much of a list), I have no idea how one would go about having some files pre-compiled and then compiling one or two other files to complete the compilation and make the "prog.exe" file. I came across this idea because I was reading about how a common practice for minimising compilation time of big programs is by only re-compiling the files you've changed. If this question is too specific or out-of-topic or a duplicate please tell me. :¬)

- 109
- 6
-
BTW, libSDL exists on Linux, which is a very friendly development environment... – Basile Starynkevitch Jul 09 '15 at 12:00
-
What was the downvote for? Was it not a reasonable question? At least tell me why – god of llamas Jul 09 '15 at 12:42
-
I did not downvote, but you obviously missed some prior research... – Basile Starynkevitch Jul 09 '15 at 12:43
-
@BasileStarynkevitch The problem with researching things like these is that google doesn't work as it's too specific and too many words. It's very difficult trying to search for something that you don't know the name of when it comes to pretty much all search engines let alone when the thing you're trying to find takes about a dozen words to describe but I appreciate that prior research is strongly encouraged to the point that it's basically a requirement before asking a question. – god of llamas Jul 27 '15 at 19:39
1 Answers
You need to learn how to use some builder program (read about build automation) like GNU make. You'll describe your build thru a Makefile
(here is an example) and make
will check the timestamps and recompile only what is needed (according to the rules and dependencies given in your Makefile
, etc...).
There are several alternative builders (e.g. omake, scons) and there exist Makefile
generators (e.g. cmake, automake)
I recommend, for a small project of a few dozen files, to code your Makefile
yourself (and not use any Makefile
generator). Use features specific to recent GNU make
, perhaps even the guile scriptability.
Dependency rules should describe header files inclusion. The -M
preprocessor options of g++
should be handy to generate them.
Look inside the source code of existing free software similar to yours for inspiration.

- 1
- 1

- 223,805
- 18
- 296
- 547