Eclipse -“这个项目不是CDT项目”

时间:2023-01-24 19:26:57

I have existing C-Code and an existing Makefile, which I want to wrap into an Eclipse C-Project (Using Eclipse 3.4 Ganymede). The Code is organized like this:

我已经有了现有的c代码和现有的Makefile,我想将它们打包到Eclipse C-Project中(使用Eclipse 3.4 Ganymede)。代码是这样组织的:

Main Directory: /Project/Software

主目录:/项目/软件

Source and Headerfiles: ../Project/Software/CodeDir1 ../Project/Software/CodeDir2 etc..

源和Headerfiles:. ./项目/软件/ CodeDir1 . ./项目/软件/ CodeDir2等。

So far I have been doing these steps:

到目前为止,我一直在做这些步骤:

  1. Set Eclipse worksapce to /Project/
  2. 将Eclipse worksapce设置为/Project/
  3. Create new C-Project with the name Software --> Now Eclipse integrates all Source files etc. into the Project
  4. 使用名称软件创建新的c项目——>现在Eclipse将所有源文件集成到项目中
  5. Go to Properties -> C/C++ Build and set to "Custom Build options"
  6. 转到属性-> C/ c++构建并设置为“自定义构建选项”

First time I do this, everything works fine. I get the output into my console and everything is cool. But then the "Build Icon" (The little hammer) is greyed out and I cant click it anymore. If I now go to the Project Properties -> C/C++ Build it just says "This project is not a CDT Project" and also I get an Error with a "java.lang.NullPointerException".

我第一次这么做,一切都很好。我把输出输入到控制台,一切都很好。但是“构建图标”(小锤子)已经变灰了,我不能再点击它了。如果我现在查看项目属性——> C/ c++ Build,它只说“这个项目不是CDT项目”,而且我还会得到一个“java.lang.NullPointerException”的错误。

How can I get a working project?

我怎样才能得到一个工作项目?

edit:

编辑:

To avoid a simple bug I tried the same with the new Version of Eclipse (Kepler). I get the same Error ("No CDT Project") but without the Null Pointer exception.

为了避免一个简单的bug,我在新版Eclipse(开普勒)上尝试了同样的方法。我得到了相同的错误(“没有CDT项目”),但是没有Null指针异常。

But I could narrow down the problem a bit: The first time I start the make process it always works. If the build process fails, I can still go to my Build Properties. As soon as I get one complete and error free build run, this issue occurs. Regarding this, it only happens when my make call is done from Eclipse. If I call it from the command line, I can still make one run out from eclipse.

但我可以把问题缩小一点:我第一次开始做make时,它总是有效的。如果构建过程失败,我仍然可以使用我的构建属性。一旦我得到一个完整的和错误的免费构建运行,这个问题就会发生。关于这一点,只有在我的make调用从Eclipse完成时才会发生。如果我从命令行调用它,我仍然可以在eclipse中运行一个。

4 个解决方案

#1


15  

If you are importing an existing CDT project and see “This project is not a CDT project”, it could be that the project was created on an older version of Eclipse, and you need to:

如果您正在导入一个现有的CDT项目,并看到“该项目不是CDT项目”,那么可能是该项目是在旧版本的Eclipse上创建的,您需要:

  • Select the project in the Project Explorer tab,
  • 选择project Explorer选项卡中的项目,
  • Click File->New->Convert to a C/C++ project
  • 点击文件->新->转换为一个C/ c++项目。

This will add a new .cproject file, and you are then ready to go.

这将添加一个新的.cproject文件,然后就可以开始了。

#2


3  

When creating your new project you need to create it as a makefile project - it will then use make to build the project but setting build properties up needs to be via your makefile and the make invocation.

在创建新项目时,您需要将其创建为makefile项目——然后它将使用make来构建项目,但是需要通过makefile和make调用来设置构建属性。

This link tells you how to create a makefile project:

这个链接告诉您如何创建makefile项目:

To create a project:

创建一个项目:

Select File > New > Project.

选择File >新的>项目。

When you create a new project, you are required to specify the project type. This project type will determine the toolchain, data, and tabs that the CDT uses/displays.

创建新项目时,需要指定项目类型。该项目类型将确定CDT使用/显示的工具链、数据和选项卡。

Select the type of project to create. For this tutorial, expand the C/C++ folder and select C++ Project. The C++ Project wizard opens. Click here to see an illustration.

选择要创建的项目类型。对于本教程,展开C/ c++文件夹并选择c++项目。打开c++项目向导。点击这里查看图示。

By default, the CDT filters the Toolchain and Project types that currently display in those lists are based on the language support for the C++ Project wizard you selected for this tutorial.

默认情况下,CDT会过滤当前在这些列表中显示的工具链和项目类型,它们基于您为本教程选择的c++项目向导的语言支持。

In the Project name field, type HelloWorld. Leave the Use Default Location option selected.

在Project name字段中,输入HelloWorld。保留使用默认的位置选项。

Next, you want to select the type of project to create. In the New CDT Project Wizard, you can choose from the following project types: Executable - Provides an executable application. This project type folder contains three templates. Hello World C++ Example provides a simple C++ Hello World application with main(). Hello World ANSI C Example provides a simple C Hello World application with main(). Empty Project provides a single source project folder that contains no files. After you select this template, the result is a project with only the meta-data files required for the project type. You are expected to provide source files for the project's target. The makefile for the Executable project type is automatically created by the CDT.

接下来,您需要选择要创建的项目类型。在新的CDT项目向导中,您可以从以下项目类型中选择:可执行-提供可执行的应用程序。这个项目类型文件夹包含三个模板。Hello World c++示例使用main()提供了一个简单的c++ Hello World应用程序。Hello World ANSI C示例提供了一个简单的C Hello World应用程序和main()。空项目提供一个不包含文件的源项目文件夹。在您选择此模板之后,结果是一个项目,其中只有项目类型所需的元数据文件。您需要为项目的目标提供源文件。可执行项目类型的makefile由CDT自动创建。

  1. Shared Library - An executable module that is compiled and linked separately. When you create a project that uses a shared library (libxx.so), you define your shared library's project as a Project Reference for your application. For this project type, the CDT combines object files together and joins them so they're relocatable and can be shared by many processes. Shared libraries are named using the format libxx.so.version, where version is a number with a default of 1. The libxx.so file usually is a symbolic link to the latest version. The makefile for this project type is automatically created by the CDT.
  2. 共享库——一个可执行的模块,分别编译和链接。当您创建一个使用共享库(libxxso)的项目时,您将共享库的项目定义为应用程序的项目引用。对于这个项目类型,CDT将对象文件组合在一起,并将它们连接起来,这样它们就可以重新定位,并且可以由许多进程共享。共享库使用格式libxxso命名。版本,其中版本是默认为1的数字。libxx。所以文件通常是最新版本的符号链接。此项目类型的makefile由CDT自动创建。
  3. Static Library - A collection of object files that you can link into another application (libxx.a). The CDT combines object files (i.e. .o) into an archive (.a) that is directly linked into an executable. The makefile for this project type is automatically created by the CDT.
  4. 静态库——可以链接到另一个应用程序(libxxa)的对象文件的集合。CDT将对象文件(例如.o)合并到一个直接链接到可执行文件的归档文件(.a)中。此项目类型的makefile由CDT自动创建。
  5. Makefile Project - Creates an empty project without the meta-data files. This selection is useful for importing and modifying existing makefile-based projects; a new makefile is not created for this project type.
  6. Makefile项目——创建一个没有元数据文件的空项目。此选择对于导入和修改现有的基于makefile的项目非常有用;没有为这个项目类型创建新的makefile。

#3


0  

The root of the problem is not located in Eclipse, it's in the makefile.

问题的根源不在Eclipse中,而是在makefile中。

The directory structure of the whole Project is the following:

整个项目的目录结构如下:

Project_Dir\Documentation\
Project_Dir\Output\
Project_Dir\Software\
Project_Dir\Tools\

The Source files are all located in the \Software\ directory. So I chose Project_Dir\Software\ as the project folder, which meant that the .project and .cproject files are located there.

源文件都位于\软件\目录中。因此我选择了Project_Dir\软件\作为项目文件夹,这意味着.project和.cproject文件位于那里。

The makefile itself temporarily writes the outputfiles in the \Software\ folder as well. In the end it copies all files from the Software dir to Output (practically a move *.* Project_Dir\Output\ command)

makefile本身也将outputfiles临时写入\Software\软件\文件夹中。最后,它将所有文件从软件目录复制到输出(实际上是一个移动*)。* Project_Dir \ \输出命令)

This command was also moving the Eclipse project-files, thus making it hard for eclipse to find them and open the project properties.

该命令还移动了Eclipse项目文件,因此使Eclipse很难找到它们并打开项目属性。

Two solutions:

两种解决方案:

  1. Change the project directory in eclipse to \Project_Dir\ since it's all project related stuff anyway
  2. 将eclipse中的项目目录更改为\Project_Dir,因为它都是与项目相关的内容
  3. Add two lines to the makefile: Before the move command: attrib +r +s *.project and attrib -r -s *.project after the move command. (Same for .cproject). This prevents the makefile from moving the files
  4. 在makefile中添加两行:在move命令之前:attrib +r +s *。项目和attrib -r -s *。项目后的移动命令。.cproject(相同)。这可以防止makefile移动文件。

#4


0  

I was able to overcome this by installing/updating corresponding CDT plugins like 'Visual C++ support'.

我通过安装/更新相应的CDT插件(如“Visual c++支持”)来克服这个问题。

#1


15  

If you are importing an existing CDT project and see “This project is not a CDT project”, it could be that the project was created on an older version of Eclipse, and you need to:

如果您正在导入一个现有的CDT项目,并看到“该项目不是CDT项目”,那么可能是该项目是在旧版本的Eclipse上创建的,您需要:

  • Select the project in the Project Explorer tab,
  • 选择project Explorer选项卡中的项目,
  • Click File->New->Convert to a C/C++ project
  • 点击文件->新->转换为一个C/ c++项目。

This will add a new .cproject file, and you are then ready to go.

这将添加一个新的.cproject文件,然后就可以开始了。

#2


3  

When creating your new project you need to create it as a makefile project - it will then use make to build the project but setting build properties up needs to be via your makefile and the make invocation.

在创建新项目时,您需要将其创建为makefile项目——然后它将使用make来构建项目,但是需要通过makefile和make调用来设置构建属性。

This link tells you how to create a makefile project:

这个链接告诉您如何创建makefile项目:

To create a project:

创建一个项目:

Select File > New > Project.

选择File >新的>项目。

When you create a new project, you are required to specify the project type. This project type will determine the toolchain, data, and tabs that the CDT uses/displays.

创建新项目时,需要指定项目类型。该项目类型将确定CDT使用/显示的工具链、数据和选项卡。

Select the type of project to create. For this tutorial, expand the C/C++ folder and select C++ Project. The C++ Project wizard opens. Click here to see an illustration.

选择要创建的项目类型。对于本教程,展开C/ c++文件夹并选择c++项目。打开c++项目向导。点击这里查看图示。

By default, the CDT filters the Toolchain and Project types that currently display in those lists are based on the language support for the C++ Project wizard you selected for this tutorial.

默认情况下,CDT会过滤当前在这些列表中显示的工具链和项目类型,它们基于您为本教程选择的c++项目向导的语言支持。

In the Project name field, type HelloWorld. Leave the Use Default Location option selected.

在Project name字段中,输入HelloWorld。保留使用默认的位置选项。

Next, you want to select the type of project to create. In the New CDT Project Wizard, you can choose from the following project types: Executable - Provides an executable application. This project type folder contains three templates. Hello World C++ Example provides a simple C++ Hello World application with main(). Hello World ANSI C Example provides a simple C Hello World application with main(). Empty Project provides a single source project folder that contains no files. After you select this template, the result is a project with only the meta-data files required for the project type. You are expected to provide source files for the project's target. The makefile for the Executable project type is automatically created by the CDT.

接下来,您需要选择要创建的项目类型。在新的CDT项目向导中,您可以从以下项目类型中选择:可执行-提供可执行的应用程序。这个项目类型文件夹包含三个模板。Hello World c++示例使用main()提供了一个简单的c++ Hello World应用程序。Hello World ANSI C示例提供了一个简单的C Hello World应用程序和main()。空项目提供一个不包含文件的源项目文件夹。在您选择此模板之后,结果是一个项目,其中只有项目类型所需的元数据文件。您需要为项目的目标提供源文件。可执行项目类型的makefile由CDT自动创建。

  1. Shared Library - An executable module that is compiled and linked separately. When you create a project that uses a shared library (libxx.so), you define your shared library's project as a Project Reference for your application. For this project type, the CDT combines object files together and joins them so they're relocatable and can be shared by many processes. Shared libraries are named using the format libxx.so.version, where version is a number with a default of 1. The libxx.so file usually is a symbolic link to the latest version. The makefile for this project type is automatically created by the CDT.
  2. 共享库——一个可执行的模块,分别编译和链接。当您创建一个使用共享库(libxxso)的项目时,您将共享库的项目定义为应用程序的项目引用。对于这个项目类型,CDT将对象文件组合在一起,并将它们连接起来,这样它们就可以重新定位,并且可以由许多进程共享。共享库使用格式libxxso命名。版本,其中版本是默认为1的数字。libxx。所以文件通常是最新版本的符号链接。此项目类型的makefile由CDT自动创建。
  3. Static Library - A collection of object files that you can link into another application (libxx.a). The CDT combines object files (i.e. .o) into an archive (.a) that is directly linked into an executable. The makefile for this project type is automatically created by the CDT.
  4. 静态库——可以链接到另一个应用程序(libxxa)的对象文件的集合。CDT将对象文件(例如.o)合并到一个直接链接到可执行文件的归档文件(.a)中。此项目类型的makefile由CDT自动创建。
  5. Makefile Project - Creates an empty project without the meta-data files. This selection is useful for importing and modifying existing makefile-based projects; a new makefile is not created for this project type.
  6. Makefile项目——创建一个没有元数据文件的空项目。此选择对于导入和修改现有的基于makefile的项目非常有用;没有为这个项目类型创建新的makefile。

#3


0  

The root of the problem is not located in Eclipse, it's in the makefile.

问题的根源不在Eclipse中,而是在makefile中。

The directory structure of the whole Project is the following:

整个项目的目录结构如下:

Project_Dir\Documentation\
Project_Dir\Output\
Project_Dir\Software\
Project_Dir\Tools\

The Source files are all located in the \Software\ directory. So I chose Project_Dir\Software\ as the project folder, which meant that the .project and .cproject files are located there.

源文件都位于\软件\目录中。因此我选择了Project_Dir\软件\作为项目文件夹,这意味着.project和.cproject文件位于那里。

The makefile itself temporarily writes the outputfiles in the \Software\ folder as well. In the end it copies all files from the Software dir to Output (practically a move *.* Project_Dir\Output\ command)

makefile本身也将outputfiles临时写入\Software\软件\文件夹中。最后,它将所有文件从软件目录复制到输出(实际上是一个移动*)。* Project_Dir \ \输出命令)

This command was also moving the Eclipse project-files, thus making it hard for eclipse to find them and open the project properties.

该命令还移动了Eclipse项目文件,因此使Eclipse很难找到它们并打开项目属性。

Two solutions:

两种解决方案:

  1. Change the project directory in eclipse to \Project_Dir\ since it's all project related stuff anyway
  2. 将eclipse中的项目目录更改为\Project_Dir,因为它都是与项目相关的内容
  3. Add two lines to the makefile: Before the move command: attrib +r +s *.project and attrib -r -s *.project after the move command. (Same for .cproject). This prevents the makefile from moving the files
  4. 在makefile中添加两行:在move命令之前:attrib +r +s *。项目和attrib -r -s *。项目后的移动命令。.cproject(相同)。这可以防止makefile移动文件。

#4


0  

I was able to overcome this by installing/updating corresponding CDT plugins like 'Visual C++ support'.

我通过安装/更新相应的CDT插件(如“Visual c++支持”)来克服这个问题。