- 2TDM-GCC
- 4Development Tools
Overview
A compiler toolchain is what Code::Blocks uses to turn the code you type into it into numbers that the computer understands. As a compiler toolchain is a very complex undertaking it is not part of Code::Blocks itself but rather is a separate project that Code::Blocks then uses. The kind of compiler toolchains talked about on this page are 'MinGW' toolchains. Which means 'Minimalist GNU for Windows.' And 'GNU' expands to 'GNU's Not Unix.' More information about the GNU project can be found on the GNU Home Page.
For most MinGW-based compiler toolchains, having your toolchain in your PATH is important because it means that during development the toolchain libraries will be accessible by default to your programs as you develop them and also makes it easier to use utilities such as CMake as they will be able to find your compiler toolchain. When you actually distribute your programs to other computers then you will copy the needed .dll files out of your toolchain directory and include them as part of your installer. On your machine they are in your PATH so you always have them, on your users computers they won't have the compiler toolchain so there you provide the .dll files with your program.
Mingw-w64 is maintained by an active open source community, so it will not be out of date. Mingw-w64 supports the latest C language standard. Mingw-w64 uses the C language runtime library of windows, so the compiled program does not need a third-party DLL, and can run. Mingw-w64ダウンロードページの中段あたりにあるMinGW-W64 Online Installerの次にあるのが、オフライン インストール用のファイルです。 ファイル名(ex: x8664-posix-sjlj )はオンライン インストーラーを使用したときの選択項目(以下の画面)に対応しています。. #MinGW A portable version of MinGW prepared for OpenGL development. Copy the MinGW folder to the root of the drive which has a project you want to compile. For example if your project is in C: Users username Documents then the MinGW folder needs to be placed in C: MinGW. Create an GNU Makefile and call it Makefile.
TDM-GCC
TDM-GCC is the toolchain that will be used as the example for this guide. TDM-GCC statically links the required toolchain libraries into your final executable. Which means that when you create your installer for your final program there are less files to include - they are built into your executable itself. The Code::Blocks team recommends TDM-GCC.
Installation
Download the on-demand installer and run it.
Go through the installation pages, the red arrows are all the default options which we will be keeping and the last blue arrow is to indicate that you will be putting TDM-GCC into your system's PATH.
Once you are ready, click Install to proceed.
Code::Blocks Configuration
Go to your Compiler settings:
And then under the 'Toolchain executables' tab (red arrow), click on the ellipsis ('...', blue arrow) and choose the root directory where you installed TDM-GCC 32-bit. Once you have that directory chosen, in the 'Program Files' sub-tab (green arrow) area fill out the fields as shown. If you aren't using the TDM-GCC toolchain there might be minor variation in the executable names. If you choose the blue arrow ellipsis first then for each ellipsis you click on under 'Program Files' you will already be in your TDM-GCC bin directory where the actual programs are.
Now, go to your Debugger settings:
Choose your default debugger (red arrow), and then fill in the Executable path for it as shown for TDM-GCC 32-bit (blue arrow).
Summary
You now have a Code::Blocks environment that is configured to use TDM-GCC 32-bit properly. Using this guide as a template you can easily set up alternative compiler toolchains no matter the source - just follow the same basic procedure.
Alternative MinGW Compiler Toolchains
MinGW - The original project.
MinGW-Builds ➡ In, 'Toolchains targeting Win32 or Win64,' ➡ 'Personal Builds,' ➡ 'mingw-builds,' ➡ Version, ➡ Threading Model, ➡ Exception Model, ➡ Revision.
Mingw-w64 - The parent project of MinGW-Builds, includes much more than is necessary - MinGW-Builds will usually suffice instead of the full works.
MinGW Equation - A package that also provides OpenMP.
Development Tools
Normally you should not need many of these tools. ZIP is convenient, especially when: building Code::Blocks itself, but other than that these tools only serve specialized purposes.
UnxUtils
GnuWin32
ZIP
- zip-3.0.0 32-bit or zip-3.0.0 64-bit
This page documents a suggested C/C++/Fortran/Python software build environment for Windows, tested on Windows 7 Professional 64-bit. The build environment is capable of building both 64-bit and 32-bit software, although some manual editing of configuration files is required to switch between the two. With some fairly obvious changes, these instructions will also work for building 32-bit software using Windows XP 32-bit.
The suggested build environment includes
- 7-zip file archive tool
- Python 2.7.5 scripting language
- MSYS, from the official MinGW project
- MinGW-w64 GCC 4.7.1 compiler suite, from TDM-GCC
- SCons 2.3.0 software build tool
- gedit 2.30.1 text editor
- SWIG 2.0.10 wrapper interface generator
- gendef (mingw-w64 svn trunk, revision 5774) linker .def file generator
- NSIS installation package builder
- Dependency Walker 2.2 library/program file dependency checker
- Subversion 1.8.0 version control software
These steps were completed by a user with administrator privileges. It is known that the Python, MinGW etc can be installed by non-administrator users, but we haven't yet tested that scenario, unfortunately. Problems may potentially arise in relation to 7-zip, gedit, NSIS or Subversion if administrator privileges are not available (but that's just guessing).
It's worth mentioning here that the 64-bit architecture for Windows that we're talking about here is alternatively referred to as x64, x64_64 and amd64. These terms all seem to be used a bit interchangeably.
First steps
- Download and install the 64-bit version of 7-zip. We used the 64-bit version, 7z920-x64.msi.
- Download and install the latest Python 2.7 release. We used the 64-bit version if 2.7.5, python-2.7.5.amd64.msi from this page. Select to install for all users, and select the default installation location, c:Python27 (although you can use another location if you already have 32-bit Python installed, but be careful to change PATH references further below if necessary).
- Note: it is permissible to install both 32-bit and 64-bit Python in the same system, and it works fine, if you're careful about setting you PATH. If you also want to build against 32-bit Python, we suggest you download python-2.7.5.msi and install it in c:Python27_32.
- Download and install the gedit text editor for Windows. We used this package: gedit-setup-2.30.1-1.exe (32-bit).
- To ensure that Windows knows that gedit is a text editor, use Windows Explorer to navigate to c:Program Files (x86)geditsharedoc and right-click on README, and select Open. In the dialog, click Browse, then select c:Program Files (x86)geditbingedit.exe, and click OK to open the file. This will ensure that gedit appears in the list of editors for other text files you want to open in future.
- Note: be aware that some other installers may modify your system PATH in a way that causes gedit to break. If you start to get errors when launching gedit, this is probably what has happened.
- Download and install NSIS. We used nsis-2.46-setup.exe. You can tell the installer not to actually run NSIS, no need for that. If you will be building ASCEND, you should also download the Inetc plugin and put the DLL from that zip file into the Plugins subdirectory where you installed NSIS.
MSYS
MinGW is a minimal GNU/GCC environment for Windows. MSYS is a command-line environment based on MinGW that mimics the Linux environment sufficiently well to allow a large portion of Linux-compatible software to also be compilable under Windows. There are many different combinations of ways to set up this environment. And things are made quite a bit more complicated by the fact that the official MinGW project does not support the 64-bit fork MinGW-w64, and as yet (Aug 2013) there is no nicely-integrated environment that supports installing everything automatically. Based on our experience in particular with difficulties in building recent versions of IPOPT, this is therefore our current preferred approach:
- Download mingw-get-setup.exe from the official MinGW (32-bit) project page (we used version 0.6.2-beta-20131004-1), and run it:
- Select to install MinGW to the directory c:MinGW32 (this is not the default location)
- Select not to install the graphical user interface
- Open gedit and edit the file c:mingw32varlibmingw-getdataprofile.xml and replace the entire contents of the file with the following text:
- From the Windows 'Start' menu open a command prompt window and run the following, which will take a few minutes:
- Using gedit, create the file c:mingwmsysetcfstab with the following content:
- Using Windows Explorer, create a shortcut to the file c:mingwmsysmsys.bat and place the shortcut on the desktop. You may wish to set the icon of the shortcut to the icon file c:mingwmsysmsys.ico.
- Double-click your new desktop shortcut to msys.bat. You should see a console window as follows:
Switchable 32- and 64-bit modes
Our setup will be a bit of a hack of the standard MinGW environment. We use the official MinGW project to provide the MSYS environment, but then we use the MinGW-w64 project (as below) to provide the actual compiler, since we want 64-bit support. Our file structure will be
- c:
- mingw (we install everything under this single top-level directory)
- 64 (the 64-bit compiler and all our 64-bit compiled-and-installed libraries will live here)
- 32 (the mingw-get binary will already be inside here, as well as the 32-bit compiler if we install it later)
- msys (the MSYS environment, and loads of useful non-compiler tools can be installed here, but they shouldn't have any binary dependencies in c:mingw64 or c:mingw32, or things will get broken!)
- mingw (we install everything under this single top-level directory)
In principle, all we need to do to switch between the 64-bit and 32-bit build environments is to edit the text file /etc/fstab (changing '32' to '64' or vice versa), then reload MSYS. In other words, if you want to now switch to 64-bit mode, you would modify /etc/fstab to read
After making this change, be sure to close and re-open your MinGW/MSYS command window (re-open it using the MSYS icon that you created on your desktop).
MinGW-w64
MinGW-w64 (Minimalist GNU for Windows, 64-bit) is a fork of the earlier MinGW GCC (GNU Compiler Collection: C, C++ and Fortran compilers and associated tools). MinGW-w-64 was carefully extended to include support for 64-bit Windows. Despite the name, MinGW-w64 both runs on and builds binaries for both 32-bit and 64-bit Windows, but you need to make sure you download the right package according to which platform you are running on, and which platform you want to target.
- Download the TDM-GCC 'MinGW-w64 sjlj' installer for from this page. We used tdm64-gcc-4.7.1-3.exe.
- Install the TDM-GCC package into the directory c:mingw64, selecting to install all components. Select not to add MinGW-w64 to the PATH.
- After the installer completes, use the Start menu, right-click on 'Computer', select 'Properties' then 'Advanced Systems Settings' then 'Advanced' tab, click button 'Environment variables'. Under system variables, edit the variable named PATH and from then end of the path, removec:mingw64bin. We don't want this in the path because it messes with gedit, and will also cause confusion when running 32-bit compilers.
- Open the MSYS shell (make sure you are in 64-bit mode, as mentioned above) by double-clicking your new desktop shortcut, and type gcc --version. You should see
- In gedit, open (or create) the file c:mingwmsyshomeyourusername.profile (no file extension). In that file, paste in the following text, and save the resulting file.
TODO: add instructions for also installing the 32-bit compilers, and instructions for getting things working on a 32-bit Windows system.
Note: the above TDM 64-bit installer does not install a fortran compiler, but a fortran compiler is required for building ASCEND. The alternative appears to be to use the latest tdm-gcc-webdl.exe downloader-installer. Select all options, but select not to install to PATH.
MinGW 32-bit compilers (optional)
For the 32-bit compilers, we will use the standard MinGW distribution. In MSYS set to 32-bit mode (see above), type:
The default MinGW 32-bit compilers use win32 threading model and dwarf2 threading.
To test the installed compiler, run
Mingw W64 Offline Installer Software
And you should see output that starts with mingw32, confirming you have the 32-bit compiler running.
Note, due to current bug 1950 in MinGW (Dec 2013), you may need to downgrade 'msys-core-bin' package to version 1.0.17 to avoid problems with parallel builds, eg make -j4. The necessary command which should probably be run from an standard Windows command prompt, is
SCons
We need to custom-build our own SCons installer from the source code, because (last time we checked), the SCons installer didn't correctly detect 64-bit Python on our system.
- Download, unpack, build and install SCons. This can be done using the MSYS window in 64-bit mode (see above):
- Step through the installer process, then return to your MSYS window and type
- To ensure that you can do parallel builds (using more than one of your processors at a time), also install pywin32, available from Christophe Gohlke's Python extensions page or from the ASCEND third-party downloads page. Use the amd64 version if you selected 64-bit Python above.
- Test that SCons is working by typing scons --version. You should get a copyright message including text to show that the you have version 2.3.0 of SCons running:
Optional: If you also want to use SCons for 32-bit packages, you can install just the downloadable 'Windows' version of SCons directly from the Scons homepage. We used version 2.3.0. If required, select to install to c:Python27_32 (the location where you installed 32-bit Python). You still need to copy the /c/Python27_32/Scripts/scons.py to /c/Python27_32/Scripts/scons as above, and you should also install pywin32, 32-bit version (from here) to ensure that parallel builds are properly supported.
Download Mingw W64 Offline Installer
Dependency Walker
- Download the 'x64' version of Dependency Walker. We downloaded this file: depends22_x64.zip. If you are also building 32-bit applications, you will also need the i686 version of Dependency Walker.
- Unpack the .exe and .dll files into the directory c:mingw64bin, for the 64-bit version and/or c:mingw32bin for the 32-bit version. By utting the files here you will automatically get access to the correct version of depends corresponding to the 32- or 64-bit mode you are running via /etc/fstab
- Test that it's working by typing into MSYS the command depends /mingw/bin/gcc.exe. A window should pop up showing the DLLs that your GCC compiler depends on.
TODO check that two versions of depends.exe are actually required! Perhaps they're not both needed, in which case we could install to c:mingwmsysbin.
SWIG
- Download a pre-compiled 'swigwin' copy of SWIG. We used swigwin-2.0.10.zip.
- Create a folder c:mingwmsysopt using Windows Explorer, then copy the 'swigwin-2.0.10' folder out of the Zip archive and into the new location c:mingwmsysoptswigwin-2.0.10
- In MSYS, type gedit ~/.profile, then add the SWIG directory to your PATH in your profile, by adding the following line at the bottom of that file:
- Close your MSYS window and reopen it, so that the ~/.profile will be re-read.
- Test that SWIG is accessible by typing swig -version. You should see the version number and some other information output.
As SWIG is a code pre-processor, it doesn't matter whether it's 32-bit or 64-bit, they will be perfectly equivalent. That is the reason that we install SWIG under msys rather than in mingw32 or mingw64. Note that SWIG version 2.0.5 was known to cause problems with MinGW-w64.
GTK+2
GTK+ is useful for developing cross-platform graphical user interface (GUI) programs. It works well under Windows, and it is the native GUI toolkit for Ubuntu, Fedora, Mint, and other Linux distributions. It has also been ported to Mac, although getting up and running on that platform is still a bit difficult. The ASCEND project provides some pre-compiled GTK+ installers that make getting started with GTK+ very straightforward.
- Download gtk+-2.22.1-20101229-x64-a4.exe from the ASCEND 'files' section, under 'thirdparty'.
- Again edit your ~/.profile file, this time add GTK, but at the end of your PATH. Add this line inside the part of the 'if' statement relating to your 64-bit setup:
- Close your MSYS and re-open it so that the updated ~/.profile is loaded.
- Test that GTK+ is working by typing either pkg-config gtk+-2.0 --libs or gtk-demo. For the latter, you should see a GUI window pop up that shows off the various GTK+ features.
Optional: To develop 32-bit applications with GTK+, download the i386 version of GTK+ from the above 'thirdparty' page, and add it to the PATH using the following line in the 32-bit part of your .profile:
Note / TODO: GTK+3 is now available (and we have been porting ASCEND to GTK+3), however we haven't tested GTK+3 on Windows up to now. There are some binaries available (64-bit and 32-bit) but they need to be repackaged for direct use on Windows, and tested.
Subversion
Subversion is a version control software. ASCEND uses it for hosting our source code, as do many other projects, especially on SourceForge.net and Google Code. SlikSvn is a nice easy-to-install packaging of Subversion software.
- Download and install the 64-bit version of SlikSVN, Slik-Subversion-1.8.5-x64.msi from the SlikSVN website. You can use the 'typical' settings and default installation location, which is c:Program FilesSlikSvn
- Edit your ~/.profile, adding the following line at the end.
- Close your MSYS and re-open it so that the updated ~/.profile is loaded.
- Check that subversion is working by typing svn --version.
It's not necessary to install both 32 and 64-bit versions of Subversion, only one is required, and it will work fine whether you're building 32-bit or 64-bit software.
Setup Python for compilation of extensions
Note: This section is only required if you want to build 64-bit Python extensions. No actions are required here if you are going to build 32-bit Python extensions.
Before you can built any Python extensions using MinGW-w64 (which includes via SWIG), some preparation is required. One C header file, pyconfig.h has to be patched, and linker definitions for python27.dll have to be prepared for the compiler. Follow these instructions to sort it out.
First download, build, and install a utility called 'gendef' which builds library *.def files that MinGW-w64 can use when linhing to DLLs. This is because the python27.lib file distributed with Python doesn't work with MinGW-w64. In your MSYS shell, type
Now prepare a new python27.def file from the installed copy of python27.dll in c:windowssystem32:
- Using Windows Explorer, copy the file c:windowssystem32python27.dll into the folder c:Python27Libs
- Using MSYS, enter the following:
If this works OK, you should have a new file c:Python27Libspython27.def.
Next, patch the c:Python27includepyconfig.h file:
- Open the file c:Python27includepyconfig.h using gedit
- Search for the text #ifdef _WIN64, which in our copy of this file was at line 141, and cut out the following three lines:
- Search for the text #ifdef _MSC_VER, which in our copy of this file was at line 107. Paste in the cut-out lines, ABOVE the #ifdef _MSC_VER. Alternatively, if you don't want to do this last step, you could just make sure you define MS_WIN64 before you #include 'Python.h' in your source code.
This issue with MS_WIN64 is reported as python bug 4709 in the Python bug tracker, so possibly it will have been fixed if you use a newer version of Python than we tested with.
We are finding that the above steps give correct behaviour on Windows 7. If future releases cause problems, the following may be useful for testing:
- swigtest.tar.gz (900 byte tarball)
- pytest.tar.gz (test of building Python bindings without SWIG, 1.1k tarball)
.profile
At the end of these steps, the .profile file (c:mingwmsyshomeyourusername.profile) will contain the following.
Usage tips
All done! You may wish to make a backup of your directory c:mingw, which contains your complete MSYS and MinGW setup, for easy reinstallation later. You would still in that case need to install SlikSVN, GTK+, Python, Scons, Gedit, NSIS, 7zip, but all of the manual fiddling about would be avoided.
When building software on this platform using GNU AutoTools, (ie, the typical './configure && make && make install' instructions), you should specify --prefix=/mingw to ensure files are installed in a path that corresponds to the 32- or 64-bit version of your compiler. This will make library linking much easier, at least while you stay within MSYS. Also, you may need to specify your build environment using the --build flag. For example,
This will have the result that libraries and new tools will be installed into c:mingw64.
If you ever want to switch building 32-bit code, recall the instructions above about #Switchable 32- and 64-bit modes. This re-routes '/mingw' to your 64-bit or 32-bit compiler and libraries according to which setting to you choose. Then, the 'if' statement in the .profile file above takes care of replacing 64-bit stuff with the 32-bit alternatives. This approach also has the result that, when running ./configure scripts, there is usually no need to add the --build flag to specify the 32- or 64-bit build architecture, as only one compiler will be visible/accessible at any one time, anyway.
Example of building a simple program
If everything is working, you should be able to enter the following simple C program into gedit, and save it into c:mingwmsyshomeyourusernametest.c:
Then compile the file and run it by typing
And you should see
TODO: expand with simple MinGW-w64 example using SCons as the build tool.