注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

TOTO

Think and Be Different

 
 
 

日志

 
 

Eclipse + CDT 手记  

2007-03-23 18:08:13|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
 

想试试在Eclipse下写C程序的感觉,所以装了个eclipse + cdt,关于它的安装,就不用我说了,装cdt的话,在help下面的updata/install,选个new feature,装就可以了,很方便的。

之后注意的是要使用windows平台下的gcc编译器,这个我选择了MinGw,其他的几个没有比较,不太清楚之间的差异。

MinGw的官方网站,把current里面的后缀为.exe的文件都下下来,装就行了,当然这也有一个规律的,如果不要做其他的,就是配合Cdt的话,那么只要找那个MinGw-*.*.exe文件就行了,装完之后把/bin目录下面的mingw32-make.exe改成make.exe即可。当然我们还要做得是类似于配置jdk的那个时候一样:

path=%path%;D:\MinGW\bin
LIBRARY_PATH=D:\MinGW\lib
C_INCLUDE_PATH=D:\MinGW\include
CPLUS_INCLUDE_PATH=D:\MinGW\include\c++\3.2.3;d:\MinGW\include\c++\3.2.3\mingw32;D:\MinGW\include\c++\3.2.3\backward;D:\MinGW\include

第一个就是在path下面添加bin路径,可以调用gcc的工具,234都是要新建的。

 

下面说下要注意的几个地方:

(1)      新建工程的时候,要建managed的,它好像是自动生成make的,standard的好像是自己写make文件,开始的时候,我配置的时候出现了问题。

(2)      一般不要让它自动生成,在Project里面可以把勾去掉

(3)      注意,Eclipse默认自动构建程序。在CDT中,每当你保存了源文件时,Eclipse都会为你构建程序。如果你觉得太麻烦,可以关闭此项功能,选择Project->Build Automatically,确保此菜单项前没有勾就行了。关闭此项功能后,你就需要在运行程序前手动编译程序。

(4)      输入完程序后保存,按Ctrl-B就能进行编译。此时底部的Console视图中会显示编译的过程。如果有错误的话在各个视图中都会有显示。如果一切正常,就可以运行程序了。选择Run As...->C Local Application,如果是第一次运行还需选择一个GDB调试器。之后程序就会运行了。 

(5)      如果要对程序进行调试,选择Debug As...->C Local Application就可以了。接下来就会进入调试透视图。界面很友好,相信不难掌握。

(6)      Ctrl-/可以注释光标所在的当前行,Ctrl-\取消注释。你也可以选中一些行以后用同样的方法对它们进行整体注释或取消注释。 

(7)      选中一些行后按Tab可以使它们整体缩进,按Shift-Tab可以取消缩进。 

(8)      按下Alt-/会出现内容辅助。如输入do再按Alt-/,就能选择do...while代码模板。这有助于加快代码输入的速度。 

(9)      选中一个变量或类型再按F3,可以跳到其被定义的地方。

(10) Console 里面查看输出结果。

可以试试那个经典的HelloWorld.c

 

      我个人认为在Eclipse下面写还是感觉不爽,连{}之类的都没有自动提示,可能这个是以后CDT的发展目标吧^_^

下面是我们国外的网站上看到的常见问题解决方法

http://max.berger.name/howto/cdt/ar01s05.jsp

Common Problems

If you have followed these instructions everything should work. However, you may have ran into trouble, and then decided to look for the manual (at least, that's the way I would have done it). So now you have a problem and need an answer:

How to fix most of the errors on Windows

Make sure you have done the following things:

  • Installed the CDT
  • Installed (not just downloaded) MinGW
  • Installed (not just downloaded) MSYS
  • Set up your path environment variable

Especially made sure you did the last step. You will need to restart eclipse. (This solves about 99% of all support mails I've got so far).

Build error (Exec error:Launching failed), CreateProcess: make -k all error=2,

You have just tried the build the hello world program, and you get this error message instead of an executable. This means that make is not in your path. Open up a command prompt (In OS X: Terminal in Applications/Utilities, in Windows: Start/Run, type in cmd) and type in make. If that doesn't work, try gmake.

If gmake worked, see the section called “Configuring the CDT”.

If neither worked, make sure you install make (See the section called “Setting up a compiler”) and set your path (See the section called “Environment Variables” in the case of Windows).

To check your path (on windows), open up cmd and type in echo %path%. This should show the path to MSYS and MinGW. Also, make sure that you restarted eclipse (or cmd if you are testing) after setting your path.

If you are on Windows, and you have installed MinGW, but not MSYS, you may have an executable called mingw-make. In this case you have to go to the section called “Configuring the CDT” and configure appropriately. It is possible to just use mingw-make and no MSYS at all, however, mingw-make has some limitations. Eclipse CDT managed makefiles may or may not work with it. Please see the MinGW FAQ for more information.

/bin/sh: line 1: g++: command not found, Error launching external scanner info generator

This error message means that g++ is either not installed or not in your path. Check your path settings as described in the section called “Build error (Exec error:Launching failed), CreateProcess: make -k all error=2,”, but this time try the commands: gcc --version and g++ --version. If gcc works, but g++ doesn't, it means you have only installed the C and not the C++ version of the gcc compiler, which happens quite frequently on Linux distributions. Check if you have all needed packages installed, and check the section called “Setting up a compiler”.

If you are on windows, and neither of them worked, install MinGW and set your path environment variable. If only gcc one worked, reinstall MinGW and don't forget to select the C++ compiler!

No output or only sometimes output

If you are on windows and use Eclipse 3.1 with CDT 3.0.0 there is a bug. see the section called “Configuring the CDT”.

Error launching 'cygpath' command

If you followed these instructions you have installed MSYS instead of cygwin. You may safely ignore this error message.

I do not have the option to start a C++ project

You have not installed the CDT. See the section called “Installing the CDT”.

Error 1, open output file blabla.exe: Permission denied

Every time I start eclipse on my laptop, I can only compile and run a program once. After that it asks if I want to run it with errors every time. The compiler says this:

Building target: Project01Test.exe

Invoking: GCC C++ Linker

g++ -oProject01Test.exe ./test.o

C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot        

open output file Project01Test.exe: Permission denied

collect2: ld returned 1 exit status

make: *** [Project01Test.exe] Error 1

make: Target `all' not remade because of errors.

Build complete for project Project01Test

Answer: Your program may still be running. Try stopping it by using the small red square on the console window (the one for your program). Another way is switching to the "Debug" perspective, selecting your running program, and stopping it there (also the small red square).

The debugger doesn't work (on windows, with MinGW)

Unfortunately gdb is not included in the current (4.1.1 or 5.0.2) version of MinGW. See the section called “GDB (optional!)”.

Incorrect command line argument: -k'

Make sure you are using the make programs provided by mingw. If your output in the console shows something like:

make -k clean all

MAKE Version 5.2  Copyright (c) 1987, 2000 Borland

Incorrect command line argument: -k

Then you have make installed from a previous installation of Borland C++. You have several choices:

  • Adjust your PATH environment variable to have the MingW / MSYS installation come before Borlands tools. Please be warned that this may break your Borland tools!
  • Remove the path to the Borland tools from your PATH. This will definitely break your Borland tools.
  • Download "mingw32-make". This is an option when installing MinGW. Make sure you set your make setting to be "mingw32-make". If you still get an error, try setting it for the build settings in your project. In this case you may even skip the installation of MSYS, but you will get limited functionality.

A Java Runtime Envrionment (JRE) or Java Development Kit (JDK) must be available...

There are several possible reasons for that:

I have no binaries

If you have no binaries folder, then two things may have happened

  • You are not looking at the C/C++ Project view. Make sure you're in the C++ perspective and the browser says "C/C++ Projects".
  • Your program didn't compile. Check the output of the "Console" Window. It is either an error in your program or a configuration error. For configuration errors, check the other problems.
  • If you do have a binaries folder, then make sure you run you program by right-clicking (on the mac: hold down ctrl and click) on the binary, and then selecting Run / Run as C/C++ Application. Just hitting the run button will only work after you have done that at least once!

Unable to access jarfile startup.jar

This problem happens on windows when you moved eclipse out of its directory instead of creating a shortcut. Please move it back into the eclipse directory, then drag'n'drop it using the right mouse button, where you can select "Create Shurtcut"

Problems not covered here

If you are still having trouble, you may try and send me an email. Please be aware that I may not respond to every email, as I am doing this support mainly as a hobby (unless you're in my class). Make sure your email includes the following. Please send the complete output!

  • The contents of your PATH environment variable (in Windows: echo %PATH%. In Linux / Mac OS X: echo $PATH).
  • Version of GCC you're using (gcc --version)
  • Version of Make you're using (make --version or gmake --version)
  • Version of Eclipse you're using
  • Version of the CDT you're using
  • The complete output of your "Console" window (at the bottom of eclipse) when your error occurs.
  • The steps you did so before the problem occured.

 

  评论这张
 
阅读(4764)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017