How do you compile C?

  • Thread starter Bob Busby
  • Start date
  • #1
47
0
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.
 

Answers and Replies

  • #2
MarcoD
I use vi, make and gcc. But I am an old-timer, wouldn't recommend it to anyone else.
 
  • #3
rcgldr
Homework Helper
8,770
569
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:
  • #4
chiro
Science Advisor
4,797
133
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.
 
  • #5
D H
Staff Emeritus
Science Advisor
Insights Author
15,415
687
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.
 
  • #6
chiro
Science Advisor
4,797
133
I remember back when I started learning to program using QB and Assembler/Machine code you had to do all the compiling and linking of stuff by hand (The assembler stuff) and when I first used Windows Visual Studio 6, it was like the transition of going from a TV without a remote to with one.

The only thing I've used in a *nix environment was pico. I'm not a linux user anyway, but at least with pico you could telnet into the environment from a windows machine and the graphics environment with pico was all hunky-dory! I remember when I used emacs on the telnet session, everything went to crap. This was for remote compilation for uni-work quite a while back though.
 

Related Threads on How do you compile C?

Replies
25
Views
13K
Replies
2
Views
2K
  • Last Post
Replies
9
Views
77K
Replies
7
Views
266
Replies
25
Views
2K
Replies
5
Views
1K
  • Last Post
3
Replies
69
Views
2K
  • Last Post
Replies
5
Views
864
Replies
4
Views
3K
Replies
10
Views
3K
Top