C语言 Eclipse - “这个项目不是 CDT 项目”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18693159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse - "This project is not a CDT project"
提问by Toby
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 项目中(使用 Eclipse 3.4 Ganymede)。代码组织如下:
Main Directory: /Project/Software
主目录: /Project/Software
Source and Headerfiles: ../Project/Software/CodeDir1 ../Project/Software/CodeDir2etc..
源文件和头文件:../Project/Software/CodeDir1 ../Project/Software/CodeDir2等等。
So far I have been doing these steps:
到目前为止,我一直在做这些步骤:
- Set Eclipse worksapce to /Project/
- Create new C-Project with the name
Software--> Now Eclipse integrates all Source files etc. into the Project - Go to Properties -> C/C++ Build and set to "Custom Build options"
- 将 Eclipse 工作区设置为 /Project/
- 使用名称创建新的 C-Project
Software--> 现在 Eclipse 将所有源文件等集成到项目中 - 转到“属性”->“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++ 构建”,它只会显示“此项目不是 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.
为了避免一个简单的错误,我对新版本的 Eclipse (Kepler) 进行了同样的尝试。我得到相同的错误(“无 CDT 项目”),但没有空指针异常。
But I could narrow down the problem a bit: The firsttime 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 freebuild 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 过程时它总是有效。如果构建过程失败,我仍然可以转到我的构建属性。一旦我得到一个完整且无错误的构建运行,就会出现这个问题。关于这一点,只有当我从 Eclipse 完成 make 调用时才会发生这种情况。如果我从命令行调用它,我仍然可以从 eclipse 中运行一个。
采纳答案by Toby
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的目录结构如下:
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 .projectand .cprojectfiles are located there.
源文件都位于\Software\目录中。所以我选择Project_Dir\Software\作为项目文件夹,这意味着.project和.cproject文件位于那里。
The makefile itself temporarily writes the outputfiles in the \Software\folder as well. In the end it copies all files from the Softwaredir to Output(practically a move *.* Project_Dir\Output\command)
makefile 本身\Software\也会临时将输出文件写入文件夹中。最后它将Software目录中的所有文件复制到Output(实际上是一个move *.* Project_Dir\Output\命令)
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:
两种解决方案:
- Change the project directory in eclipse to
\Project_Dir\since it's all project related stuff anyway - Add two lines to the makefile: Before the move command:
attrib +r +s *.projectandattrib -r -s *.projectafter the move command. (Same for.cproject). This prevents the makefile from moving the files
- 将 eclipse 中的项目目录更改为,
\Project_Dir\因为它无论如何都是与项目相关的东西 - 在 makefile 中添加两行:在移动命令之前:
attrib +r +s *.project和attrib -r -s *.project在移动命令之后。(同样适用于.cproject)。这可以防止 makefile 移动文件
回答by mirams
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 Explorertab, - Click File->New->Convert to a C/C++ project
- 在
Project Explorer选项卡中选择项目, - 点击 File->New->Convert to a C/C++ project
This will add a new .cprojectfile, and you are then ready to go.
这将添加一个新.cproject文件,然后您就可以开始了。
回答by Steve Barnes
When creating your new project you need to create it as a makefileproject - 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 linktells you how to create a makefile project:
这个链接告诉你如何创建一个 makefile 项目:
To create a project:
Select File > New > Project.
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.
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.
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.
In the Project name field, type HelloWorld. Leave the Use Default Location option selected.
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.
- 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.
- 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.
- 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.
创建项目:
选择文件 > 新建 > 项目。
创建新项目时,需要指定项目类型。此项目类型将决定 CDT 使用/显示的工具链、数据和选项卡。
选择要创建的项目类型。对于本教程,展开 C/C++ 文件夹并选择 C++ 项目。C++ 项目向导打开。单击此处查看插图。
默认情况下,CDT 筛选当前显示在这些列表中的工具链和项目类型基于您为本教程选择的 C++ 项目向导的语言支持。
在项目名称字段中,键入 HelloWorld。保持选中使用默认位置选项。
接下来,您要选择要创建的项目类型。在 New CDT Project Wizard 中,您可以从以下项目类型中进行选择: Executable - 提供一个可执行的应用程序。此项目类型文件夹包含三个模板。Hello World C++ 示例提供了一个带有 main() 的简单 C++ Hello World 应用程序。Hello World ANSI C 示例提供了一个带有 main() 的简单 C Hello World 应用程序。Empty Project 提供了一个不包含任何文件的源项目文件夹。选择此模板后,结果是一个仅包含项目类型所需元数据文件的项目。您需要为项目的目标提供源文件。Executable 项目类型的 makefile 由 CDT 自动创建。
- 共享库 - 单独编译和链接的可执行模块。创建使用共享库 (libxx.so) 的项目时,您将共享库的项目定义为应用程序的项目引用。对于此项目类型,CDT 将目标文件组合在一起并连接它们,以便它们可重定位并可由多个进程共享。共享库使用 libxx.so.version 格式命名,其中 version 是一个数字,默认值为 1。libxx.so 文件通常是指向最新版本的符号链接。此项目类型的 makefile 由 CDT 自动创建。
- 静态库 - 您可以链接到另一个应用程序 (libxx.a) 的目标文件集合。CDT 将目标文件(即.o)组合成直接链接到可执行文件的存档 (.a)。此项目类型的 makefile 由 CDT 自动创建。
- Makefile Project - 创建一个没有元数据文件的空项目。此选择对于导入和修改现有的基于 makefile 的项目很有用;不会为此项目类型创建新的 makefile。
回答by Sergei
I was able to overcome this by installing/updating corresponding CDT plugins like 'Visual C++ support'.
我能够通过安装/更新相应的 CDT 插件(如“Visual C++ 支持”)来克服这个问题。

