G++(GNU C++)安装及使用

一 安装

 

安装步骤:

1、下载 Cygnus 的G++编译器(http://www.claremontmckenna.edu/math/ALee/g++/full.exe),并保存到E盘(或其它任意盘),格式为E:full.exe

2、直接运行该文件,可能需要十几分钟的时间(中间会有停顿甚至没有任何提示性图片或者符号,需要耐心等待哦)。

      或者Win + R ,输入cmd,按Enter键进入命令行模式;输入E:按Enter转入E盘;输入文件名称full运行文件。

3、定位G++安装后文件夹bin的位置,这里为E:/cygnus/cygwin-b20/H-i586-cygwin32/bin。设置环境变量如下:我的电脑->属性->高级->环境变量,可在Administrator的用户变量系统环境变量中找到Path(大小写均可),点击编辑,在其后面加上“;E:/cygnus/cygwin-b20/H-i586-cygwin32/bin”,必须加上分号,且为英文半角符号。 最后点击确定退出。

4、开始菜单中如果出现Cygnus Solutions 表示安装成功了。

参考文献:

1、http://www.claremontmckenna.edu/math/ALee/g++/g++.html

2、http://www.cppblog.com/heidaizx/articles/33582.html

 

二 使用

1、 单一文件编译

(1)使用UltraDdit创建并编辑hello.cpp(文件位置为E:/source/hello.cpp),内容如下:

(2)按Win + R ,输入cmd,按Enter键进入命令行模式;     

   输入E:按Enter转入E盘;   

     输入cd  source,转入source文件夹;   

     输入g++ Hello.cpp -o hello ,编译并链接;          

 输入hello运行文件,此时在屏幕上会显示“Hello World !”。

2、多个文件编译(1)使用UltraDdit创建并编辑Hello.h, Hello.cpp, MyFirst.cpp ,内容如下:  

(2) g++中有一个参数-c 可以只编译不连接,那么我们就可以按如下顺序编译文件 按照相同的步骤转入source文件夹;

依次键入

g++ -c hello.cpp -o hello.o

g++ -c myfirst.cpp -o myfirst.o

g++ myfirst.o hello.o -o myfirst

然后输入myfirst运行程序。截图如下:

Installing c++/g++ on Windows Disclaimer: This page is being maintained mainly for my students. Use these instructions at your own risk. There is no warranty in any form or shape whatsoever!. There is no guarantee that these instructions are up-to-date. With that understood you may continue with the rest of this page if you choose to accept these terms. This page was last updated on September 13, 2005, but still good as of April 30, 2009. Follow these steps to install g++ (the GNU C++ compiler) for Windows. There is no room for creativity here; you must follow the directions exactly. Pick the drive and a folder in which you want to install g++. I'll assume that it is C:, but you can choose a different one. If you choose a different drive or a different folder, you'll need to adapt the directions below accordingly. Download full.exe, an about 14 megabyte executable, to C:\full.exe by right-clicking on the link. Use Save Link As... or Save Target As... Be sure the browser saves the file as C:\full.exe. Run the downloaded executable. This will install g++ (and a lot of other things that you don't really need) on your hard drive. Go to the C: drive using Windows Explorer and double-click on full.exe. Or, open a DOS window (Start > Programs > Command Prompt), connect to the C: drive using the cd command, and type full. Locate where the bin folder was created for the g++ installation. On my Windows XP machine, it was created in the following path: C:\cygnus\cygwin-b20\H-i586-cygwin32\bin You now should add it to the PATH environment variable. You do that by following: Start -> Control Panel -> System -> Advanced -> Environment Variables At this point you can see the PATH variable either in the User Variables or in the System Variables. Add the g++ path into the PATH variable. You add it to the end of the existing value separated by a semicolon (';'). Make sure that you do not lose the original value. You are just appending more to the end separated by a semicolon. Restart your computer. A Cygnus Solutions entry will appear in your Programs menu, and an icon may appear on your desktop. Don't use them! You will use it using the g++ command on a DOS prompt as explained below. You should now be able to run g++ from a DOS (Command Prompt) window. For example, to compile a file called C:\mine\hello.cpp, connect to the C:\mine folder and enter g++ -g hello.cpp -o hello -lm You'll then be able to run the compiled program by entering hello in the DOS window. If you've installed Emacs as described here, you will also be able to run g++ from Emacs. If, when you do this, Emacs tries to compile with the command make -k, you made a mistake during the Emacs installation. If you want to learn how to run g++ on emacs, see here. If you'd like to learn more about where this free compiler came from, we downloaded it from an older site of http://sourceware.org/cygwin/. If you wish to clean up a little, you may delete the file: full.exe at this point. Your g++ compiler is installed under C:\cygnus.
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值