论坛首页 编程语言技术论坛

Windows下用Eclipse搭建C/C++开发环境

浏览 194417 次
精华帖 (0) :: 良好帖 (6) :: 新手帖 (5) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-12-31   最后修改:2010-01-02
C++
本文假定你已经熟悉Java,Eclipse的安装,并能顺利启动和运行Eclipse.此外因为各软件版本在不断更新,有些地方可能不准确,以最新的、原文资料为准。

距上一次写和调C++程序,已经5、6年了,光阴荏苒岁月无情,现在再重新拾起来,很多东西都要从头来。Windows下C/C++的IDE有很多,我知道的就有MS Visual Studio,Borland C++等,但这些是要版权的。不要钱也有一些,但因为对Eclipse太熟了,所以就选下面要讲的Eclipse + GNU toolchain(话说toolchain这个词很形象).

1. 首先下载Eclipse for C++, 最新版是基于Eclipse 3.5.1的,叫做galileo(伽利略),受不了这种奇怪的名字了,为什么不叫布鲁诺?上个版本3.4貌似叫做ganymede(木卫三)。下载地址:http://eclipse.org/downloads/,选择32bit for windows,文件名叫 eclipse-cpp-galileo-SR1-win32.zip



2. 解压,直接运行。注意,至少JDK你已经安装了(我用的是JDK1.6)。运行后一个灰蓝色的welcome页面出现,进入Tutorials。学东西先读Tutorial是个好习惯。

3. 首先了解一下什么是CDT,就是 C/C++ Development Toolkit,bulabula... 然后它说,这个东西没包含C/C++的编译器、调试器,你得自己弄。

4. 那就继续看。Windows下,MinGW和Cygwin 是获取GNU toolchain的2种主要方式(GNU toolchain,GNU下一系列的工具包,我的理解主要是gcc这一系列工具)。这两者最大的区别是MinGW使用Windows C的运行库,叫做mscvrt,而Cygwin使用了一组基于GPL的DLLs(GPL协议具有传染性,使用GPL协议下的软件后你自己开发的东西也要遵守GPL协议),因此MinGW避开了GPL协议。

5. MinGW和CDT能很好的整合。好吧,我们装MinGW(MinGW是Minimal GNU for Windows的意思,这个下载过程相当慢,我下了大半个小时)。当前版本是MinGW-5.1.6.exe,我一股脑来了个Full install。装完后才发现这么一句:Do not install the MinGW Make feature as the MSYS version of make from step 5 is a more complete implementation of make.(不要安装MinGW的Make, 第5步的MSYS是个更好的实现方案)

6. 为了避免将来可能遇到的问题,卸了重装。这里是完整的安装步骤:
1)下载MinGW,地址 http://sourceforge.net/projects/mingw/files/
2)安装MinGW base tool和g++编译器(不要安装Make);我把除了Make之外的都装了,里面居然还有个Ada的编译器


3)当前版本(它是指MinGW-5.1.3,不过我下的5.1.6同样也没有)没有装gdb debugger, 下载它:http://downloads.sourceforge.net/mingw/gdb-6.6.tar.bz2
4)解压gdb-6.6.tar.bz2 到你安装MinGW的地方,gdb-6.6/下也有一系列bin,inclue文件夹,直接拷到MinGW下面覆盖进去即可
5)如果要用Makefile,请下载 MSYS-1.0.10.exe,MSYS是make及命令行的一个实现。嗯,要用。下载地址 http://downloads.sourceforge.net/mingw/MSYS-1.0.10.exe
安装界面是个命令界面,写2个”y”,然后告知MinGW的安装路径即可。


OK,安装部分就完成了。下面写2个小例子。

7. 首先创建一个简单的HelloWorld C++工程,这个很简单,按Wizard向导建一个模板即可。


Run的时候选Run Configurations, 然后双击C/C++ application建一个新的run configuration就行。


8. 下面建一个Makefile类型的工程。选择New C++ Project -> Makefile project -> Empty Project, 我们建一个空的项目,建完后里面什么也没有(除了2个.project文件),这时,我们要建一个源文件和一个make文件:main.cpp 和 makefile,如下,都建到根目录下:

/*
 * main.cpp
 */

#include <iostream>
using namespace std;

int main () {
    // Say Hello five times
    for (int index = 0; index < 5; ++index)
      cout << "HelloWorld!" << endl;
    char input = 'i';
    cout << "To exit, press 'm'" << endl;
    while(input != 'm') {
        cin  >> input;
        cout << "You just entered " << input
             << " you need to enter m to exit." << endl;
    }
    exit(0);
}

all: hello.exe

clean:
	rm main.o hello.exe

hello.exe: main.o
	g++ -g -o hello main.o

main.o:
	g++ -c -g main.cpp

注意,makefile里的行首缩进用的是Tab而不是空格。如果编译时提示 No separator...就是这里有问题。

9. Ok, 选中工程,点Build(或点那个小锤子),你会发现这个错误:(Cannot run program "make": Launching failed),啊,我们的make.exe还没设。选中工程,直接Alt-Enter到工程属性页,把msys的bin加到Path里。


10. 重新build, 大功告成。
   发表时间:2010-01-05  
现在在Eclipse上开发C/C++越来越简单了
想当初还要自己写makefile才能运行
0 请登录后投票
   发表时间:2010-01-05  
visual studio 2008 express是不需要版权的。
而且,即使不用这个,我认为也可以试试
devcpp,codelite,codeblocks
0 请登录后投票
   发表时间:2010-01-06  
七猫 写道
visual studio 2008 express是不需要版权的。
而且,即使不用这个,我认为也可以试试
devcpp,codelite,codeblocks

你听谁说是不需要版权的。。。。
0 请登录后投票
   发表时间:2010-01-06  
上次也下了个eclipse C++,但是发现无法编译,就放弃了,原来eclipse C++不自带编译器。
不错的帖子。
0 请登录后投票
   发表时间:2010-01-06  
很实用,也很详尽,楼主辛苦了
0 请登录后投票
   发表时间:2010-01-06  
mikeandmore 写道
七猫 写道
visual studio 2008 express是不需要版权的。
而且,即使不用这个,我认为也可以试试
devcpp,codelite,codeblocks

你听谁说是不需要版权的。。。。



http://www.microsoft.com/express/support/faq/



General Questions
What are the Visual Studio Express Editions?

The Visual Studio Express Editions are an expansion of the Visual Studio and SQL Server product line to include fun, simple and easy-to-learn tools for non-professional developers like hobbyists, students and novice developers who want to build dynamic Windows applications, Web sites, and Web services. The Express products consist of:
Visual Basic 2008 Express Edition - Productivity that is ideal for first time or casual Windows programming
Visual C# 2008 Express Edition – A great combination of power and productivity for the Windows developer
Visual C++ 2008 Express Edition – Horsepower with a finer degree of control than other Express Editions
Visual Web Developer 2008 Express Edition – An easy-to-use environment for dynamic Web application development
SQL Server 2008 Express and SQL Server Compact Edition – A powerful and easy-to-use set of databases to complement each Express Edition
What can I do with the Visual Studio Express Editions?
Learn how to program using a streamlined, lightweight development environment
Create fun and cool applications using the C4F Developer Kit, C4F Vista P2P Developer Kit, Facebook Developer Kit or share projects with the Popfly Explorer.
How much will these products cost?

Effective April 19th, 2006, all Visual Studio Express Editions are free permanently. This pricing covers all Visual Studio 2005 Express Editions and Visual Studio 2008 Express Editions including Visual Basic, Visual C#, Visual C++, Visual J# (only available in Visual Studio 2005 Express), and Visual Web Developer as well as all localized versions of Visual Studio Express.
Where can I find out the latest issues and bugs?

Visit the Readme document for more information on bugs and known issues relating to Visual Studio Express Editions.
How long do I have to register?

You'll have 30 days from when you install your Visual Studio Express Editions.
Can you give me more information about the Registration process?

Visit the Registration Benefits Web page as well as the Registration FAQ page.

看这里:再发布是可以的。本身免费,开发出来的软件可以再发布。
Can I use Express Editions for commercial use?


Yes, there are no licensing restrictions for applications built using Visual Studio Express Editions.

How are Express Editions different from the rest of the Visual Studio and SQL Server Editions?

Express Edition products are designed for hobbyists, students, and novice developers. As such, they lack the full breadth of features found in higher-end Visual Studio and SQL Server Editions. They are designed specifically for scenarios common to the hobbyist, student, and novice developer. Each Express Edition includes targeted documentation that will help the beginning programmer quickly learn the concepts required to build more advanced applications. The user interfaces are significantly streamlined to ensure that extraneous features do not interfere with the learning process. If you later decide that you do need additional features available in the higher-end editions of Visual Studio and SQL Server, you can seamlessly upgrade your code and skills.
Where can I go for more information about the Express Editions?

We have created a Web site with content and drill-down information on the product line. You can also get the latest information using the product-specific RSS feeds:
Visual Basic 2008 Express RSS feed
Visual C# 2008 Express RSS feed
Visual C++ 2008 Express RSS feed
Visual Web Developer Express RSS feed
Where can I report bugs or make a product suggestion?

Please report bugs or suggestions to the Product Feedback Center.
Are the Express Edition products supported?

SQL Server Express is covered under standard Microsoft support policies. Support is offered on a per incident charge. For assistance with other questions, please use the following support options:
We have created Express Edition Forums where you can get help from other people using the Express Editions, including Microsoft product team members.
You can access paid professional support over phone or e-mail.
If your organization has Premier support contracts, you can use those for assistance with VS express products.
What is the MSDN 2008 Express Edition Library?

The MSDN Express Library contains additional product documentation and code samples for all Visual Studio Express Editions
How can I install the MSDN 2008 Express Edition Library?

The MSDN 2008 Express Edition Library is available as a separate download from the Visual Studio Express installers. Click here to download the MSDN Express Library
0 请登录后投票
   发表时间:2010-01-06  
下个这个插件org.eclipse.cdt-2.1.1-win32.x86.zip 再装MinGW-5.1.6.exe就行了吧
0 请登录后投票
   发表时间:2010-01-07  
真奇怪,eclipse官方怎么不自带一个编译器
0 请登录后投票
   发表时间:2010-01-08  
- -  MinGW 只选g++ 即可
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics