Aled Jones
6 posts
Non-involved compiling
Edited by Aled Jones on Reason: Initial post
I want to just compile without hassle. Literally just write my code then press ctrl-m.

.bat files require you to write out every file you use

same with cmake

any solutions?
Allen Webster
473 posts / 4 projects
Heyo
Non-involved compiling
There's no such thing as a magical build system that *just works* in the land of C++ unfortunately.

Approximates to the *just works* are:
unity build - just include all your cpp files into one other cpp file, build just that one file
cl *.cpp - build all with a wild card

even these will become problems eventually... c'est la vie
Aled Jones
6 posts
Non-involved compiling
How do you compile? A long list of .cpp and .h files in a .bat file?
Allen Webster
473 posts / 4 projects
Heyo
Non-involved compiling
I generally go the unity build route for as long as I can. When I have to get back compilation speed I do it by moving a large chunk into a separate static (.lib/.a) or shared (.dll/.so) file and I have different scripts for each chunk (or something like that).

If you're not familiar with the unity build, it's just where you go:
cl <all my options> my_target_file.cpp

Then in the target file you'll see something similar to:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // TOP #include "foo.h" #include "bar.h" #include "baz.h" // maybe some code, maybe not #include "foo.cpp" #include "bar.cpp" #include "foobar.cpp" // probably more code int main(){ // etc } // BOTTOM 

Of course if you wanted to avoid a list of files you haven't really achieved that, it's just an include list instead of a .bat list, but this does just work out nicer anyway. It makes fewer .obj files. It's a nicer syntax, at least for me. You get an error jumping you to the correct file and line when there's a misspelling.

If you're really worried about having to list all your .cpp and .h files, you can still just do "cl *.cpp", but I think the list of files is worth it.
78 posts
None
Non-involved compiling
@Allen
What problems did you have with the unity build?

One problem I ran into with the unity build was an IDE I was using at the time didn't understand it, so no fancy code completion and other things like that. So I saw no reason to use IDEs after that.

@Aled
Just recently I was able to understand make files. I found an article written by a university professor that explained them so I understood them. If you are interested I will hunt it down.

Understanding would be the best chance of having something that just works, but unity builds are what you want if you want the fastest builds.