It’s been quite some times since I began learning C and C++ but I’ve been very limited only to the Windows platform and the Visual Studio environment. Recently, I wanted to look into some open source C/C++ projects, so I downloaded a few but I was frustrated because I didn’t know how to compile those software. Then I had to learn about all those g++
and make
stuff and still I only have very limited knowledge in those subjects.
Having been used to an environment like Visual Studio, where you can write the code, hit the play button and boom you’re all good to go, it was hard for me to compile a program with the command line at first.
So my question is, if you’re a C/C++ developer, how do you compile your code ? How do you compile relatively large code bases ? What are the tools that you use ? Do you use IDEs or simply text editors ? What is the compiler that you use ? Do you build your applications from the command line ? What is the OS that you usually compile on ?
SideNote: My linux knowledge is zero.
6
At least for free software on Linux, you usually use some builder like make
. You could use some other builder program, like scons or omake
For some (mostly historical) reasons, the Makefile
may be generated by utilities like autoconf
or cmake
; these generators also deal with configuration issues (e.g. they disable some features of the software if a dependency is missing). Some frameworks also provide their own Makefile
generators, e.g. qmake for Qt
PS. Recent GNU make 4 has a lot of new features (plugins and guile scriptability) which are worthwhile (and probably could IMHO remove the necessity of generating Makefile
-s).
When building large C++ code base, I recommend using command line utilities (notably make
), because you understand more what is really happening. Also, a lot of large C++ code bases are sometimes using specialized C++ code generators (e.g. the GCC compiler has a dozen of them, internal to it). There are good reasons to sometimes generate some C++ code (perhaps with a simple awk or python script), e.g. some headers or constants, etc.
To build many GNU -or other- large free software bases -at least on Linux-, you generally don’t need to understand all the details of their building. Usually, a README
or an INSTALL
text file explains how to do that, and it is often -for software using autoconf- (but not always) as simple as running the three commands
./configure
make
sudo make install
You might prefer to run make install DESTDIR=/tmp/installdir/
then copy the /tmp/installdir
with e.g. sudo cp -va /tmp/installdir/ /
For software using cmake, building them is often as simple as
mkdir build
cd build
cmake ..
make
sudo make install
The pkg-config is also a useful utility, since it gives the compilation and linking flags useful with some packages.
Large software may be difficult to build because of the dependency hell (which is an issue for every large software, on any operating system). Linux distributions are done to manage with it.
I guess that these free software are often easier to build on Linux than on Windows (which I don’t know and never use). BTW, I strongly recommend you to install Linux and learn it, because it is fun and made of free software (whose source code you can study, improve, and contribute to).
Very large or foundational free software like the GCC compiler, the GNU glibc, the Linux kernel are tricky to build (because nearly everything depend upon them). So start building some easier free software from source code. See sourceforge or github to find some.
Some languages or frameworks have their own installer or package manager or builder. For example, ocaml has opam
BTW, notice that all IDE (including Visual Studio on Windows) are just editors with some graphical interface to run the C++ compiler on the command line. So it is better to understand what is really happening, by knowing how to run the compiler thru commands.
2
My experience is that beyond having a Makefile (or sometimes cmake :-(), it varies according to the personal tastes of the individual. Personally, I use a editor that runs from the command line (xterm), and have editor macros (created over a couple of decades) that more or less imitate many of the features of an IDE without the baggage. For instance, one keypress runs make (after saving all open files), dumps the output into a file which I see in the editor, then another keypress on an error line takes me to the originating line in the source. (And this works for other things, like LaTeX documents.) Other people like to use vi(m), emacs, or other tools.
The common core is that almost everything I’ve seen builds from a Makefile. If the project is intended for wide distribution, that may be generated by autoconf tools. (Or cmake &c.) However, if you like IDEs, Wikipedia has a long list that run in Linux: https://en.wikipedia.org/wiki/Category:Linux_integrated_development_environments I’ve no experience with any of them, other than a short (and unpleasant) stint with Eclipse – and that some years ago, so it may well have improved.