Setting up compiler in Windows Eclipse for cpp

Setting up a compiler

Prev

 

 Next

Setting up a compiler

Unfortunately Eclipse only provides theIntegrated Development Environment (IDE) but it is missing the actual compiler.To install a compiler, please follow the instructions for your operatingsystem.

Windows compiler

Windows doesn't come with a build-in compiler.You could try to install Visual Studio, but it is tricky to get that workingwith Eclipse. Therefore we will installMSYS. MSYS is part of theMinGW suite, which provides free development tools for Windows.

You will have to follow these 4 steps:

Download and install MinGW

Download and install MSYS

Set your path environment variable

Restart Eclipse if it was started.

MinGW

First, you need to download MinGW. You caneither click through the websites mentioned above or go directly to theMinGW downloadarea. Lookfor the Package "Automated MinGW Installer". There, download the fileending in .exe. The file name should be something like "MinGW-5.1.4.exe".You can also downloadMinGW Version5.1.4 fromthe link given here.

You may also download an older version, andfollow the instructions given inthe sectioncalledOlderInstructions:

You may download MinGW 4 and follow the instructionsin the sectioncalledMinGW 4.x.

You may download MinGW 3 and follow the instructionsin the sectioncalledMinGW 3.1.

Most of the options in the MinGW 5 installerare pretty straightforward. I will point out some of the more tricky options.

The first one of such options is which"MinGW" package to install. Any of those should work just fine, but Iwould recommend Current.

Figure1. MinGW 5 install



MinGW will ask which components to install.Either select All or at least make sure that you have the g++ compiler checked.This is needed for C++ support.

Figure2. MinGW 5 install (2)

 

When asked for the install folder, please donot change it. You will have a lot of trouble later on, especially if you chosea path that contains spaces.

Figure3. MinGW 5 install (3)

 

That's already it for MinGW. There are two moresteps: MSYS and the Environment Variables.

Checkpoint: To test if everything worked,please reboot. Then open up a terminal. (Start/Run, type CMD). Try thesecommands:

gcc--version

 

should print the version of gcc. If you get a"File not found", try logging out and logging back in, or evenrebooting your computer. If it still does not work, you have not installedMinGW correctly. You may also need to set your environment variables manually(see below).

g++--version

should print the version for g++. You didselect the "g++ compiler" I hope. If not, install again!

GDB (optional!)

This section is completely optional. You mayskip it and go directly tothe sectioncalledMSYS.

If you want to use the debugger, you may haveto install it separately. This is the case with MinGW 5.0.2, it may bedifferent in other versions. Download it from the same page, look for a packagestarting with gdb and ending with .exe. At the time of this writing (Apr 29)the current version was "gdb-5.2.1-1.exe". Install (double-click)that .exe, select all the default options (make sure you select the same MinGWdirectory as you did during the MinGW install).

I have received a report that gdb-6.3-2 doesnot work. So I would advise using the older version or waiting for a newer one.

Checkpoint:

gdb--version

should print the gdb version. This is optional.

MSYS

Unfortunately MinGW is not enough. We also needthe MSYS tools from the same download page. Go there again, to the"Current" section and look for "MSYS Base System". Again,look for the file ending in .exe, as this time: "MSYS-1.0.11.exe".You may have to expand the "Release Candidate" section. Or you mayuse the link here toMSYS-1.0.11.exe. Download it and start it.You should get a window like this:

Figure4. MSYS install

 

If you accept all the default options, after awhile there should be a black and white window, similar to this:

Figure5. MSYS asking for postinstall

 

To continue the install type in y and thenEnter. The next question reads like this:

Figure6. MSYS asking for MinGW

 

Which you can also answer with y Enter. Thenext question is a little bit more tricky:

Figure7. MSYS asking for path to MinGW

 

What they want to know is where you installedMinGW to and that you replace all backward slashes (\) by forward slashes (/).If you followed the instructions, the answer here will be:

C:/MinGW

Caveat: If you have not used the default paths,but instead have installed MinGW in a different location, such as C:/ProgramFiles/MinGW, where the path contains spaces and / or is longer than 8characters you may have to replace that particular path component with its DOSshort pathname, such as C:/PROGRA~1/mingw.

Caveat2: The installer may be case sensitive.Please make sure you have written MinGW in the same capitalization as duringyour first install, in some cases you will have to enter c:/mingw (notecapitalization!).

The very last question just asks you to press akey:

Figure8. MSYS installing correctly

 

Where you can press any key you like tocontinue. Setup will come back and ask you if you want to read a welcome noteand the README file. You probably don't want either one, but it does not hurtto look. Anyways, once you hit "Finish" you are done with the setup.Now you have to set up your Path environment variable.

Figure9. MSYS is done


Environment Variables

The next thing you need to do is set up yourPath environment variable. To do so, right-click on My Computer and selectProperties. Then, select the Advanced tab. There should be a button calledEnvironment Variables.

Figure10. Finding Environment Variables (Windows 2000)

 

Figure11. Finding Environment Variables (Windows XP)

 

In the environment variables, there are twosections, one for the local user (you) and one for the system. Depending onwhether you want the paths to be set for everyone, or for you, do one of thefollowing:

Warning: I had reports ofpeople deleting their existing Path environment variable! Please be verycareful when editing an existing value! By default, Windows has the whole lineselected, resulting in overwriting what was in there!

If you want to set it for everyone, look forthe variable Path in the section System variables. Click Edit. There should alreadybe some stuff in there, append;C:\msys\1.0\bin;C:\mingw\bin(or your appropriate paths) to it, and select OK multiple times. Please makesure that you do not overwrite what was in there!

If you just want to set it for you, look forPath in the upper section. It is very likely not there yet. So select New...and enterC:\msys\1.0\bin;C:\mingw\bin(or your appropriate paths). Then select OK multiple times. Again, if there wasa setting before, do not delete it, but rather append your path!

There seems to be a problem with a very longPATH environment variable on some systems. According to reports, Eclipse willfail to compile and build, where as compiling and building from a commandwindow may work fine. In this case, try to prepend the path to MinGW and MSYSrather than appending it.

Congratulations. Now you have a complier andmake set up on your computer. Continue withthe section calledSetting upEclipse.

Checkpoint: Open up a command terminal (cmd)and type:

make--version

This should work now. If not, you have eithernot installed MSYS correctly or not set your path environment variable. Also,try logging out and back in.

Linux / Unix Compiler

In most Linux and Unix distributions the compileris already installed. Check if you can run

g++--version

and either

make--version

or

gmake--version

If both of them (g++ and eithermake or gmake) work then you are already done.If not, please install those. This may be very different depending on whichLinux or Unix distribution you have. Install the tools and continue withthe section calledSetting upEclipse.

Mac OS X Compiler

On Mac OS X you can also try the commandsexplained inthe sectioncalledLinux / UnixCompiler to check if you have thenecessary tools installed. If not, you will need to install the developertools. They are either on one of your Mac OS X CDs that came with yourcomputer, or you can download them at:Apple'sdeveloper connection.

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值