# How do you compile C?

IDEs are bloated and slow usually and makefiles are confusing to write by myself. I was just wondering what you experts do to organize and compile projects with.

MarcoD
I use vi, make and gcc. But I am an old-timer, wouldn't recommend it to anyone else.

rcgldr
Homework Helper
Depends on how complex the project is. Note that Visual Studio includes a dos console window under programs / ... visual studio ... / tools, where you can use cl and link (and ml if you want to do assembly programs). If it's just a single module, I just use cl. If it's a few modules, I create a batch file.

For the most complex setup I've used at work, the user can create an empty directory and get a single batch file that will get everything needed from version control and do a build. In some cases that same batch file can be used with an existing directory, only updating anything that is out of date (mostly makefile). The batch file gets the build tools, (nmake, ml, cl, link, ...), via version control, sets environment variables, creates the entire directory tree, then switches to a large makefile that gets source files if not present or out of date, then does the actual build process. The build tools are included so that old code is built with the same versions of the tools used to originally build the old code.

One trick in the batch file for real dos or dos console windoes to allow it to be used with either empty or existing directories is the ability to test for the existance of a directory by looking for a file named "nul" in that directory:

Code:
if not exist exampledirectory\nul    md exampledirectory

I don't recall being able to duplicate this with an makefile, but once the directories are created, then the makefile has no problem checking for existance of files or out of date files.

In addition to visual studio, old copies of visual c 4.0 (32 bit) and 2.2 (16 bit), are used to work with old projects.

Last edited:
chiro
IDEs are bloated and slow usually and makefiles are confusing to write by myself. I was just wondering what you experts do to organize and compile projects with.

You should understand that many IDE's call separate processes that compile different source files and link these modules to create an EXE, DLL, or other binary object.

Usually what can happen is that the IDE calls these processes and simply pipes the output to an output window of some sort.

If you have a decent computer (not top of the line, but average), this should not be a major issue.

D H
Staff Emeritus
I use vi, make and gcc. But I am an old-timer, wouldn't recommend it to anyone else.
Also an old-timer, so take my comments with a grain of salt.

vi/vim can be fairly magical, particularly when you have magic enabled. On the other hand, vim (who uses vi nowadays?) is a rather dimwitted editor, even with ctags (which don't work quite so well with an OO language where names intentionally overlap). I like the command line concept in vim versus the popups that tend to pervade IDEs; I find that those popups to be slow, distracting, and disconcerting. Some people justifiably do like the added power of an IDE, and find the modal behaviors of vi, vim and emacs to be distracting and disconcerting.

Regarding makefiles, I sometimes have to use external tools that write makefiles. (Using an IDE in these situations can be a bit tough, when the external tool and the IDE contend over who owns the makefile.) When I am in control, if the makefile is simple I just write the makefile. If the makefile will be of any complexity, I will either
• include some master makefile I have written earlier and add the few lines need to make that master makefile work. I find this approach to be very useful for unit tests. My unit test makefiles tend to be very small thanks to the include capability.
• Build a Configure script that generates a top level makefile in some project. This top level makefile will inevitably contain a makefiles target that invokes some secondary script to build makefiles in applicable subdirectories, each of which has a makefiles target as well.
The underlying machinery can be a bit convoluted, but usage is simple: Just type make.

chiro