Installing the Cygwin Toolset in Borland C++ BuilderX
By Daniel Horn
Introduction:
Borland C++ BuilderX (BCBX) includes a powerful IDE in which a
developer can add an arbitrary collection of tools, a toolset, with which to
build their projects. We will take a specific toolset, Cygwin,
and add it to BCBX under Windows.
Using an existing toolset as a model, it is a fairly straightforward
procedure to add a new toolset. The basic procedure is to copy the set of
configuration files for an existing toolset that is similar to your new toolset
and modify them.
What follows is a brief description of my experiences doing this, some of the
additional details you will need to know to work successfully with Cygwin, as
well as a few things to watch out for.
Caveats:
This work was done using the first release of Borland C++ BuilderX running
under Windows XP.
The sample toolset and tool files (in the zip file located at http://codecentral.borland.com/codecentral/ccWeb.exe/listing?id=21245) and the work described in this paper provide just enough
functionality to use the Cygwin tools to compile, link, and debug the
"Welcome" sample program that appears when you first launch BCBX.
Mileage may vary: there is no guarantee that all of the functionality you need
will be provided. In fact, if you want functionality that is a proper
superset of that provided by MinGW, then you will almost certainly have to make
additional changes to the tool files.
Neither Borland nor Cygwin had anything to do with the work contained in this
paper; no official endorsement by either should be assumed.
What is Cygwin?
Cygwin is a set of tools similar to those normally available on Linux but
available for Windows. The available tools include such items as gcc, g++,
gdb, make, ar, bash, and less.
Download and Install Cygwin:
Before we begin, you'll need to download and install Cygwin from its web site
http://www.cygwin.com/. I used
version 1.5.5-1 which was the latest version at the time of this writing.
What you download is actually a small program, setup.exe. Running it is fairly self-explanatory.
Though you can do it in one fell swoop, when I used it, I chose to run it in two
passes:
- first, to select and download the components I wanted (on the "Choose
Installation Type" page of the setup, choose "Download from
Internet");
- second, to perform the actual installation ("Install from Local
Directory" on the "Choose Installation Type" page).
Note that the development tools are not selected by default in the setup
program. On the "Select Packages" screen of the setup, expand the "Devel" category and choose the actual tools you want. In my case,
I choose gcc (GCC C compiler), gcc-g++ (GCC C++ compiler), make, gdb (GNU
debugger), bison (a yacc compatible parser generator), and byacc. Adding these will automatically add other dependent tools such as binutils (assembler, linker, and other utilities).
In the version I used, there was a bug in the setup that missed a necessary
dependency. So to avoid trouble, also select the "libpcre0: Perl-Compatible Regular Expressions library" item
under "Libs".
The install creates a menu item and icon on your Windows desktop for starting a Cygwin bash
shell. Alternatively, if you prefer to run from an ordinary command line
session under Windows, you'll need to add the appropriate cygwin directories to
your path. For example, the sample batch file has the following:
set path=c:/cygwin/usr/local/bin;c:/cygwin/usr/bin;c:/cygwin/bin;c:/cygwin/usr/X11R6/bin;%PATH%
In practice, all that I really needed to add was "c:/cygwin/bin" as
no tools were actually installed in the other locations.
After running the install, try a simple test to make sure that the components
are installed correctly. My test was simple. I just tried to run
some of the tools, like "less".
Note that you may receive an error message (as I did) saying that a dll, cygpcre-0.dll, could not be found.
This is the setup bug I mentioned earlier. To fix, just run the setup
again and add the missing component (in this case, the "libpcre0: Perl-Compatible Regular Expressions library" item
under "Libs").
The final point to be aware of here is that you can always run the setup at
any time later on to add any missing or newly desired component. I
initially forgot to add the gdb debugger for Cygwin and this was all I had to do
fix the problem.
Adding the New Toolset to Borland C++X:
The toolsets used by BCBX are located in your /CBuilderX/toolsets directory.
To get started, I decided to use a similar toolset as a model, that is, I
copied the files associated with MinGW toolset (MinGW is the minimalist version of the GNU
tools for Windows development) which is included with BCBX when
installed on Windows. In particular, I copied the "MinGW.toolset"
file to a new file named "Cygwin.toolset" and I copied the "MinGW"
subdirectory to a new subdirectory named "Cygwin".
If you compare the new versions of the toolset and tool files (in the .zip
file associated with this article at http://codecentral.borland.com/codecentral/ccWeb.exe/listing?id=21245)
with the
originals, you'll notice that all I changed were names, descriptions, and paths.
If you restart BCBX, you can see that these tools are automatically loaded by
selecting the Tools | Build Tools... menu item.

If BCBX is already running, just choose "Tools | Reload Toolsets"
whenever you add or modify a toolset.
Using the New Toolset:
Let's use our new toolset to compile and link a Windows program.
Before doing this, I wanted to make sure that I actually used the new Cygwin
tools instead of the preinstalled MinGW tools. I renamed my "C:/CBuilderX/mingw"
directory to "C:/CBuilderX/1mingw" to ensure that any path or
directory settings that might accidentally use them will fail to find
them.
*** If you do this too, remember to give the directory back its
original name when you are all finished testing.
To test the new toolset, open the Welcome.cbx sample project that comes with BCBX. Right click on "Welcome.cbx" in the project pane and choose the Build Options Explorer.
Change the toolset from "Borland Win32 Compiler Tools" to the newly added "Cygwin for Windows".
Then try to rebuild the project.
The first time I tried this I received an error message box with the caption "cc1plus.exe - Unable to Locate Component" and message "This application
failed to start because cygwin1.dll was not found." This error message
indicated that
I needed to add the cygwin/bin directory to my path which you can do within BCBX using the Project | Project Properties ...
dialog. In the "Variables" tab, you can modify the path; I added "c:/cygwin/bin"
near the front of my path to ensure that any name conflicts resolve first to
those provided by Cygwin.
Debugging:
To debug the program built with the toolset, you will need to make one additional
change to your project.
Open Project | Project Properties... and choose the "Debug" tab.
Choose the "General" tab (within the "Debug" tab) and verify that the "Default debugger of toolset" item is selected in the "Debugger" combobox.
(The debugger that works with the toolset is determined by the
"debugger" tag in the toolset file.)
Then choose the "GDB Debugger" tab to set the location of the action gdb executable (e.g.,
C:/cygwin/bin/gdb.exe) .
(If not already selected, choose the Debug Build configuration for the
program and rebuild to make sure that debug information is available).
Then set a breakpoint in your program and start it in the debugger. (If
your breakpoints don't work, check that the path to gdb is correct and that
debug info was actually created).
Using Other Tools:
I also used the Cygwin toolset to build a project created using File | New...
| Project from Make.
There were only two issues here needed for this to work:
- right click on the "Makefile" in the project pane, choose
Properties, and
set the "Make Program" to the correct path to the make utility.
- add c:/cygwin/bin to the project's path variable (in Project Properties |
Variables).
What's Next:
For more authoritative information on toolsets, look for the "Build Tools and Toolsets" and "Adding
Custom Toolsets" topics in the BCBX help. Also, the toolsetdoc.html and tooldoc.html files in the
/CBuilderX/toolsets directory document the XML schemas used in .toolset and .tool files.
Note that I chose to start with the MinGW toolset. For your work, you might prefer to
use the gnucplus toolset or the tool files in the gnucplus or gnucommon
directories as your starting point. In practice,
you might find that your Cygwin toolset takes elements from both gnucplus and
mingw. For example, you might add a <canexecuteonidehostplatform> tag for
windows to a toolset file similar to gnucplus.toolset.
Questions, comments, and suggestions may be sent to the
author at dan@nerds.com ; use the title of the article or the words BDN
Article in the email subject.
Connect with Us