4coder » Forums » Non-involved compiling
Aled
Aled Jones
6 posts
#14331 Non-involved compiling
8 months ago Edited by Aled Jones on Feb. 22, 2018, 12:23 a.m. 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?
Mr4thDimention
Allen Webster
424 posts / 2 projects

Heyo

#14332 Non-involved compiling
8 months ago

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
Aled Jones
6 posts
#14336 Non-involved compiling
8 months ago

How do you compile? A long list of .cpp and .h files in a .bat file?
Mr4thDimention
Allen Webster
424 posts / 2 projects

Heyo

#14340 Non-involved compiling
8 months ago

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.
Mór
78 posts

None

#14343 Non-involved compiling
8 months ago

@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.

None