Code::Blocks

Mac OS X

On Mac, I downloaded codeblocks-8.02-mac.zip from http://www.codeblocks.org/. As part of the installation process, it autodetected the GNU GCC Compiler.

To compile the half-C++, half-C program in Chapter 1, §1.7.2, pp. 83–84, consisting of the three files fg.h, main.C, and fg.C,

File → New → Project… → Console Application → Go

I named the project Project1 and saved it in a folder named Project1 on my desktop. The project already had a main.cpp file under “Sources”. I overwrote it with this main.cpp and pulled down File → Save. To add fg.h and fg.c to the project,

Project → Add files… → Open
When it said “Select the targets this file should belong to”, I checked Debug and Release and pressed OK.

To run the project,

Build → Build and run
This caused a new Terminal window to appear, shown below, containing the standard output of the program.
Last login: Fri Jun 26 15:31:37 on ttys006
/Users/scholar/Desktop/Project1/Project1/bin/Debug/Project1 
ND-IMAC-02:~ scholar$ /Users/scholar/Desktop/Project1/Project1/bin/Debug/Project1 
f
20
ND-IMAC-02:~ scholar$

The terminal test program on Mac OS X

To compile the terminal test program in Chapter 1, §1.7.3, pp. 85–89, create a Console Application project consisting of the three files main.C (renamed main.cpp), term.h, and term.c. Uncomment the #define UNIX in term.c and say
File → Save

Windows 7

Go to http://www.codeblocks.org/downloads, click on Download the binary release, and download codeblocks-10.05mingw-setup.exe from Sourceforge.net.
Welcome to the CodeBlocks Setup Wizard.
Select the type of install: Full
Next
It installed into C:\Program Files (x86)\CodeBlocks.

The terminal test program on Windows 7

File → New → Project…
Console application
Go
Project title: Term
Folder to create project in: Make New Folder. I named it Term and put it on the Desktop.
Project filename: Term.cbp
Resulting filename: C:\Users\Myname\Desktop\Term\Term\Term.cbp
Next
Compiler: GNU GCC Compiler
Finish

Open the Sources folder of the project. Open the main.cpp file. Overwrite the contents of the project’s main.cpp with this main.C.

Select the Sources folder.
File → New → File…
C/C++ header
Go
Next
Please select the language for the file: C
Next
Filename with full path: C:\Users\Myname\Desktop\Term\Term\term.h
Add file to active project in build target(s): All
Finish
Open the Headers subfolder of the Term folder. Open term.h. Overwrite the contents of term.h with this term.h.

Select the Sources folder.
File → New → File…
C/C++ source
Go
Next
Please select the language for the file: C
Next
Filename with full path: C:\Users\Myname\Desktop\Term\Term\term.c
Add file to active project in build target(s): All
Finish
Open the Sources subfolder of the Term folder. Open term.c. Overwrite the contents of term.c with this term.c.

Uncomment the #define MICROSOFT directive at the start of term.c. Add system("PAUSE"); immediately before the return from main in main.cpp.

Settings → Compiler and debugger… → Toolchain executables
Compiler’s installation directory: Auto-detect
It autodetected C:\Program Files (x86)\CodeBlocks\MinGW
Build → Build and run

Windows XP Professional

Windows was similar to Mac. I downloaded codeblocks-8.02-setup.exe. As part of the installation process, it detected one compiler: the Microsoft Visual C++ 2005/2008 compiler. But it set the default compiler to the GNU GCC Compiler.

As I created the project, it said “Please select the compiler to use and which configurations youi want to enable in your project.” It offered the GNU GCC Compiler, but I selected the Microsoft Visual C++ 2005/2008 compiler instead. I added system("PAUSE"); immediately before the return from main and saved the file with File → Save.

When I said

Build → Build and run
I didn’t see any output. The only way I got output was to go into the Windows Command Prompt, cd down to the bin subdirectory of the Debug directory where the .exe file was, and run the .exe file by hand.

The terminal test program on Windows XP

To compile the terminal test program in Chapter 1, §1.7.3, pp. 85–89, create a Console Application project consisting of the three files main.C (renamed main.cpp), term.h, and term.c. Uncomment the #define MICROSOFT in term.c. Add system("PAUSE"); immediately before the return from main in main.cpp. Save each file with File → Save.

When I said Build → Build and run, it complained that it could find the header file windows.h included by term.c. This header is in the directory C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include on my machine. I added this directory to the list of search directories:
Project → Build options… → Search directories → Compiler
and Added the directory.

The next time I said Build → Build and run, it said “fatal error LNK1181: cannot open input file 'Files\Microsoft.obj'”. When I clicked on Build log, it seemed to be confused by the four blanks in the directory name C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include Any ideas? Can I create a shortcut to this directory with a name that has no blanks? Or do I have to reinstall Visual Studio in a directory whose name has no blanks?