首页 | 文章中心 | 下载中心 | 本站特供 | 软硬件结合论坛 | 软硬件结合博客 | 
您现在的位置: 中国软硬件结合技术网 >> 文章中心 >> 软件技术 >> VB、JAVA等 >> 正文 用户登录 新用户注册
[图文]Using CDT With Cygwin          【字体:
Using CDT With Cygwin
作者:Nikolay Koustov    文章来源:    点击数:    更新时间:2005-12-30

Using CDT With Cygwin

--------------------------------------------------------------------------------

Just a few random hints for now...

--------------------------------------------------------------------------------

Setting the PATH

Installing CDT recommends setting the Windows PATH to include the cygwin bin directory. This is sufficient, if your program does not need extra library paths, but if you need additional paths, you have two options of dealing with this situation:

add the additional paths to the Windows PATH as well (Windows style; cygwin will convert them to UNIX style), or

set the PATH environment variable in eclipse's launch configuration. Since the content of this variable is used only inside GDB, it has to contain only those elements applicable to the UNIX/cygwin world. I find the latter much easier, especially while using different library directories during tesing and debugging.

If a program debugged within cygwin/gdb can't locate a required library, you may experience strange behaviour: instead of seeing the standard message box of cygwin's ld which indicates a missing library, you will only see the message "You can't do that without a process to debug." in eclipse's debug console.

Additional notes (eclipse 3.1 + CDT 3.0 + CygWin 5.1 + g++ 3.4.4)

It took me a while to get up and running with the bundle that I stated above. Partly because I had CDT installed first. Then I knew I was missing the toolchain. Then I had trouble with Cygwin missing the libraries and the header files, etc. There is little or no information on the web on how to do it right the first time. So I hope someone will benefit from what I will write below. And hopefully we will see some attention to this area from the CDT developer's community.

C++ Project types

First of all, new CDT has two main types of projects: Managed Make and Standard Make.

The major difference is that in the Managed Make mode CDT will generate the make file for you, and if you are new to C++/make, it'll save you some time to get your first HelloWorld program running. All you need to do is write your C++ code. Then you simply use the Project Build and Run menu commands within eclipse itself to do the rest. Well, you may need to tweak some parameters if you are planning to use third party libraries like CppUnit and XercesC, or if you want the code you created with the new Class wizard to compile. Read more on this below.

The downside of the Managed Make configuration is that you are somewhat limited in using other toolchains (compiler/linker/etc.) like Visual C++, Borland C++ Builder and the likes. Also, the famous facility to link in the source code from outside the main location for the project file is not yet supported in this case.

Other than that I believe, the Managed Make configuration is what you want if you are new to CDT or C++ or both.

By now I have tried both options and they work equally well (when configured properly). I envisage most of the newbies to start with the Managed Make and then moving onto the Standard Make configuration if they need more control over the entire process.

Configuring your C++ environment

It seems the developers of CDT have done a great job to ensure as seemless integration with g++ as possible. If you have Cygwin installed with all the necessary header and object files for development by the time you install CDT, it will automatically discover the location of the files and will configure your C++ projects so you don't have to make it yourself. It works in most of the cases, for example if you do not need libraries that are not part of Cygwin distribution itself.

You can do some fine tuning of what is configured by default and this will become global settings for your CDT installation so things like code templates, code formatting, the Build command and parameters etc. are all configured in here. The path is Windows -> Preferences ... ->C/C++.

One important setting that you will need at first is the File Indexer to allow the code completion/file search/etc. I recommend you to enable the Indexer by choosing Indexer -> Full C/C++ Indexer. The indexer will eventually kick in to build the index and will consume CPU for some time, but you will gain a lot from it later on.

Start your first project by creating a Managed Make C++ project by doing File -> New -> Other -> C++ -> Managed Make C++ Project. Just put in the project name you like and leave the rest unchanged. You should see that the system auto discovered some header files for you in the Cygwin installation directory (you need to have Cygwin installed first!). If you don't, something has gone wrong and most likely you will need to reinstall CDT after you have got a working copy of Cygwin.

Configuring your Managed Make C++ project to compile / build your code

The compiler

If you are planning to use some libraries that are not part of Cygwin installation, you will now need to tweak your environment so the compiler can see the header files that you are going to include in your source code to reuse the library.

Right click on the project you just created, select Properties in the context menu or else just go to Project -> Properties....

Select C/C++ Build -> GCC C++ Compiler -> Directories -> Include path. Add here the full path to directories with the header files of the libraries you will use for your project that are not part of Cygwin installation.

One thing I discovered is that it seems the Indexer may be able to go into subdirectories within the main include directory of Cygwin (e.g. c:\cygwin\usr\include) and thus bring you up the classes that are part of Cygwin but are not the core C++ libraries. A good example of this could be the CppUnit library that sits under c:\cygwin\usr\include in its own cppunit subdirectory. You will be able to look up the header files with the Class wizard and so when a new class has been created the referenced classes will be included in there without the relative path to the main include directory. This is where the problem lies - You won't be able to compile the generated files !

To get around this problem either always include the relative path to the header files, i.e. and not just . This means some changes to the generated code - Doh! Or else you may want to extend the list of directories the compiler will look up by using the Project Properties wizard just like you did before.

The Linker

The final yet important bit is to configure your project so the linker can resolve the references in the actual object libraries. This is not necessary for the core libraries like Standard C++ library, but is required for libraries like CppUnit or XercesC although they are part of the Cygwin installation and ironically reside in the same directory in Cygwin.

In the dialog window select C/C++ Build -> GCC C++ Linker -> Libraries and look up the section at the bottom right called 'Libraries search path'. Add the full path to the standard libraries supplied with Cygwin, i.e. c:\cygwin\lib.

Then you need to add the libraries that you will want the linker to look up in the specified directory to resolve references by using 'Libraries' section at the same level (C/C++ Build -> GCC C++ Linker -> Libraries). The trick here is that you only need to provide the library's short name, e.g. cppunit for CppUnit or xerces for XercesC. CDT will resolve the correct file name itself.

If the library of your choice is not part of Cygwin, you'll need to specify the full path there and then.

Compiling and Building your first C++ program

To compile and build your project select Project -> Build Project. Assuming that you have configured the project to resolve all the nessasary dependencies you should be able to have an executable ready to run.

To run your project select Run -> Run ... Select C/C++ Local Application. Click New. Select your project and then browser the project to find and select the generated executable. Click Run.

Author: Nikolay Koustov, 13/09/2005.

文章录入:Polylove    责任编辑:Polylove 
  • 上一篇文章: 软件项目开发管理

  • 下一篇文章: vb知识
  • 发表评论】【告诉好友】【打印此文】【关闭窗口
          最新热点       最新推荐       相关文章
    没有相关文章
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)