How to configure Eclipse "Helios" with plugin CDT for cmake?
如何为cmake配置插件CDT的Eclipse“Helios”?
cmake all
CMake Error: The source directory "D:/javaworkspace/workspace/Planner/Debug/all" does not exist.
Eclipse always wants to use 'all' option and I don't know how to stop its to not use it.
Eclipse总是希望使用“all”选项,我不知道如何停止使用它。
I've seen that in "Build behavior" section, in "Preference" there have been 'all' option. I erased this, but it still works wrong (this same error).
我已经看到在“构建行为”一节中,在“偏好”中有“所有”选项。我擦掉了这个,但它仍然是错误的(同样的错误)。
5 个解决方案
#1
21
In Eclipse-CDT you do not create cmake projects but you import cmake projects. This is what you should do:
在Eclipse-CDT中,您不创建cmake项目,而是导入cmake项目。这是你应该做的:
-
Say the source of your CMake project named "Planner" is located in
D:/javaworkspace/src/Planner
假设您的CMake项目名为“Planner”的源代码位于D:/javaworkspace/src/Planner中。
-
Create a folder (the folders NEED to be parallel to each other):
D:/javaworkspace/build/Planner
创建一个文件夹(文件夹需要相互平行):D:/javaworkspace/build/Planner。
-
Go to the folder
D:/javaworkspace/build/Planner
and run CMake using the Eclipse generator:转到文件夹D:/javaworkspace/build/Planner,使用Eclipse生成器运行CMake:
cmake ../../src/Planner -G"Eclipse CDT4 - Unix Makefiles"
This will generate the make files for your Planner project.
这将为您的计划项目生成make文件。
-
To import this in Eclipse do the following:
要在Eclipse中导入此操作,请执行以下操作:
File -> Import -> Existing code as Makefile project
文件->导入->现有代码为Makefile项目。
and select
D:/javaworkspace/build/Planner
(the build output folder with the make files) as the "Existing Code location"并选择D:/javaworkspace/build/Planner(以make文件为构建输出文件夹)作为“现有代码位置”
However, looking at your paths it seems to me that you are working on Windows. In windows CMake can generate Visual Studio projects. If you want to use CMake I suggest first creating a "hello world" project using CMake (remember, Eclipse does not create CMake projects, you have to create a CMakeLists.txt file by hand)
然而,看着你的路径,我觉得你是在Windows上工作。在windows CMake中可以生成Visual Studio项目。如果您想使用CMake,我建议您首先使用CMake创建一个“hello world”项目(记住,Eclipse不创建CMake项目,您必须创建一个CMakeLists。txt文件手工)
#2
5
What worked best for me is cmake4eclipse. It's a plugin that is available via the marketplace.
对我最有效的是cmake4eclipse。它是一个通过市场提供的插件。
Portions from the cmake4eclipse help text:
cmake4eclipse帮助文本的部分:
CMake for CDT requires an existing C/C++ project to work with. It allows to use cmake as the generator for the makefiles instead of the generator built-in to CDT. See Enabling CMake buildscript generation for details.
CMake对CDT需要一个现有的C/ c++项目。它允许使用cmake作为生成文件的生成器,而不是CDT内置的生成器。有关详细信息,请参见启用CMake构建脚本生成。
To set up a new project with existing source code, please follow these steps:
要用现有的源代码建立一个新的项目,请遵循以下步骤:
- Check out your source code.
- 检查你的源代码。
- Open the new C/C++ project wizard ("File" => "New" => "C Project" or "File" => "New" => "C++ Project").
- Make sure the project location points to root directory of your checked out files
- 确保项目位置指向已签出文件的根目录。
- For the project type, select Executable. You may also select Shared Library or Static Library, it does not matter, that information comes from your CMakeLists.txt, but CDT requires it. Do not select Makefile project here!
- 对于项目类型,选择可执行文件。您还可以选择共享库或静态库,这并不重要,这些信息来自您的CMakeLists。txt,但CDT要求它。不要在这里选择Makefile项目!
- Finish project creation.
- 完成项目创建。
- 打开新的C/ c++项目向导("File" => " new " => "C项目"或"File" => " new " => " c++项目")。确保项目的位置指向您的项目类型的签出文件的根目录,选择可执行文件。您还可以选择共享库或静态库,这并不重要,这些信息来自您的CMakeLists。txt,但CDT要求它。不要在这里选择Makefile项目!完成项目创建。
- Open the "Project Properties" dialog.
- Select the "C/C++ Build" node and the "Builder Settings" tab and make sure Generate Makefiles automatically is checked.
- 选择“C/ c++构建”节点和“Builder设置”选项卡,并确保自动生成makefile。
- Select the "Tool Chain Editor" node and set "CMake Make Builder" as the current builder.
- 选择“工具链编辑器”节点,并将“CMake Make Builder”设置为当前构建器。
- If your top level CMakeLists.txt does not reside in the root directory of your checked out files, select the "C/C++ General" "Path and Symbols" node and the "Source Location" tab. Then adjust the source folder to point to the directory containing your CMakeLists.txt file. This will tell the CDT indexer to scan the header files in your project.
- 如果你的*CMakeLists。txt不会驻留在您的签出文件的根目录中,选择“C/ c++通用”“路径和符号”节点和“源位置”选项卡。然后调整源文件夹,指向包含CMakeLists的目录。txt文件。这将告诉CDT索引器扫描项目中的头文件。
- 打开“项目属性”对话框。选择“C/ c++构建”节点和“Builder设置”选项卡,并确保自动生成makefile。选择“工具链编辑器”节点,并将“CMake Make Builder”设置为当前构建器。如果你的*CMakeLists。txt不会驻留在您的签出文件的根目录中,选择“C/ c++通用”“路径和符号”节点和“源位置”选项卡。然后调整源文件夹,指向包含CMakeLists的目录。txt文件。这将告诉CDT索引器扫描项目中的头文件。
- Pro Tip: Add a CMakeLists.txt file in the root directory of your checked out files, if you miss the Binaries or Archives folder in the C/C++ Projects View. Build the project. This will invoke cmake to generate the build scripts, if necessary, and then will invoke make.
- 专业提示:添加一个CMakeLists。txt文件在您的签出文件的根目录中,如果您错过了C/ c++项目视图中的二进制文件或档案夹。构建项目。这将调用cmake来生成构建脚本,如果有必要的话,然后调用make。
Do not try to import an Eclipse project that you created manually using cmake -G Eclipse CDT4 - Unix Makefiles, as that will put you on the classic Makefile project route!
不要试图导入您使用cmake - g Eclipse CDT4 - Unix Makefile手工创建的Eclipse项目,这将使您在经典的Makefile项目路径上获得成功!
The best thing about this plugin is that it can use the cmake exported compiler options to index your project.
这个插件最好的地方是它可以使用cmake导出的编译器选项来索引您的项目。
- Open the "Project Properties" dialog.
- Select the "C/C++ General" node and the "Preprocessor Includes Paths, Macros etc." tab. Select "CMAKE_EXPORT_COMPILE_COMMANDS Parser" and move it to the top of the list.
- 选择“C/ c++通用”节点,“预处理器包括路径、宏等”选项卡。选择“CMAKE_EXPORT_COMPILE_COMMANDS解析器”并将其移到列表的顶部。
- Hit "OK" to close the dialog. Make sure to trigger one build now and recreate the index.
- 点击“确定”关闭对话框。确保现在触发一个构建并重新创建索引。
- 打开“项目属性”对话框。选择“C/ c++通用”节点,“预处理器包括路径、宏等”选项卡。选择“CMAKE_EXPORT_COMPILE_COMMANDS解析器”并将其移到列表的顶部。点击“确定”关闭对话框。确保现在触发一个构建并重新创建索引。
This fixed all the nasty indexer problems that were annoying me when I only used "CDT GCC Build-In Compiler Settings" and added stuff like "-std=c++14" to "Command to get the compiler specs".
当我只使用“CDT GCC内置编译器设置”和添加诸如“-std=c++14”到“命令获取编译器规范”之类的东西时,这些烦人的indexer问题就被解决了。
#3
3
Using CMAKE in Eclipse Makefile project(on win):
在Eclipse Makefile项目(win)中使用CMAKE:
1) create new "Makefile Project with Existing Code"
1)创建新的“Makefile项目与现有代码”
2) modify builder settings(Project Properties->C/C++ Build->Builder Settings):
2)修改生成器设置(项目属性->C/ c++ Build-> builder设置):
-
Build command: cmd /c "mkdir ${PWD} & cd /D ${PWD} && ${CMAKE} -G "Unix Makefiles" ${ProjDirPath} && make"
Build command: cmd /c "mkdir ${PWD} & cd /D ${CMAKE} -G "Unix makefile " ${ProjDirPath} && make"
-
Build directory: ${workspace_loc:/IoT_SDK}/build/${ConfigName}
构建目录:$ { workspace_loc:/ IoT_SDK } /构建/ $ { ConfigName }
That's all!
这是所有!
#4
1
In addition to accepted answer you should specify eclipse version.
除了接受的答案之外,您还应该指定eclipse版本。
Eclipse Luna (4.4):
Eclipse卢娜(4.4):
cmake -G"Eclipse CDT4 - Unix Makefiles" -D_ECLIPSE_VERSION=4.4 ../../src/Planner
Eclipse Kepler (4.3):
Eclipse开普勒(4.3):
cmake -G"Eclipse CDT4 - Unix Makefiles" -D_ECLIPSE_VERSION=4.3 ../../src/Planner
#5
1
Another completely different method.
另一个完全不同的方法。
-
Manually create an empty Eclipse project.
手动创建一个空的Eclipse项目。
-
Link source directory via Project Properties -> C/C++ General -> Paths and Symbols -> Source Location.
链接源目录通过项目属性-> C/ c++通用->路径和符号->源位置。
-
In the Debug and Release build directories create 'Make Targets' (using the 'Make Targets View'). Leave 'Make Target' field empty and set the 'command' field to
cmake -G "Unix Makefiles" <path/to/the/sources>
.在Debug和Release构建目录中创建“Make target”(使用“Make target View”)。离开“使目标”字段为空,并将“命令”字段设置为cmake -G“Unix makefile” <路径 to 源> 。
-
When you double-click on the 'Make Target' that you've created, it should trigger cmake invocation inside the Debug/Release dirs.
当您双击创建的“Make Target”时,应该在Debug/Release dirs中触发cmake调用。
-
In 'Project Properties -> C/C++ Build' disable built-in makefile generator.
在'项目属性-> C/ c++构建'禁用内置makefile生成器。
Now normal build should work. It will also pick up any changes in the CMakeLists.txt files (to the extent that CMake can).
现在正常的构建应该工作。它还将在CMakeLists中获得任何更改。txt文件(到CMake可以的程度)。
Maybe a more detailed description: https://*.com/a/38140914/4742108
也许是更详细的描述:https://*.com/a/38140914/4742108。
#1
21
In Eclipse-CDT you do not create cmake projects but you import cmake projects. This is what you should do:
在Eclipse-CDT中,您不创建cmake项目,而是导入cmake项目。这是你应该做的:
-
Say the source of your CMake project named "Planner" is located in
D:/javaworkspace/src/Planner
假设您的CMake项目名为“Planner”的源代码位于D:/javaworkspace/src/Planner中。
-
Create a folder (the folders NEED to be parallel to each other):
D:/javaworkspace/build/Planner
创建一个文件夹(文件夹需要相互平行):D:/javaworkspace/build/Planner。
-
Go to the folder
D:/javaworkspace/build/Planner
and run CMake using the Eclipse generator:转到文件夹D:/javaworkspace/build/Planner,使用Eclipse生成器运行CMake:
cmake ../../src/Planner -G"Eclipse CDT4 - Unix Makefiles"
This will generate the make files for your Planner project.
这将为您的计划项目生成make文件。
-
To import this in Eclipse do the following:
要在Eclipse中导入此操作,请执行以下操作:
File -> Import -> Existing code as Makefile project
文件->导入->现有代码为Makefile项目。
and select
D:/javaworkspace/build/Planner
(the build output folder with the make files) as the "Existing Code location"并选择D:/javaworkspace/build/Planner(以make文件为构建输出文件夹)作为“现有代码位置”
However, looking at your paths it seems to me that you are working on Windows. In windows CMake can generate Visual Studio projects. If you want to use CMake I suggest first creating a "hello world" project using CMake (remember, Eclipse does not create CMake projects, you have to create a CMakeLists.txt file by hand)
然而,看着你的路径,我觉得你是在Windows上工作。在windows CMake中可以生成Visual Studio项目。如果您想使用CMake,我建议您首先使用CMake创建一个“hello world”项目(记住,Eclipse不创建CMake项目,您必须创建一个CMakeLists。txt文件手工)
#2
5
What worked best for me is cmake4eclipse. It's a plugin that is available via the marketplace.
对我最有效的是cmake4eclipse。它是一个通过市场提供的插件。
Portions from the cmake4eclipse help text:
cmake4eclipse帮助文本的部分:
CMake for CDT requires an existing C/C++ project to work with. It allows to use cmake as the generator for the makefiles instead of the generator built-in to CDT. See Enabling CMake buildscript generation for details.
CMake对CDT需要一个现有的C/ c++项目。它允许使用cmake作为生成文件的生成器,而不是CDT内置的生成器。有关详细信息,请参见启用CMake构建脚本生成。
To set up a new project with existing source code, please follow these steps:
要用现有的源代码建立一个新的项目,请遵循以下步骤:
- Check out your source code.
- 检查你的源代码。
- Open the new C/C++ project wizard ("File" => "New" => "C Project" or "File" => "New" => "C++ Project").
- Make sure the project location points to root directory of your checked out files
- 确保项目位置指向已签出文件的根目录。
- For the project type, select Executable. You may also select Shared Library or Static Library, it does not matter, that information comes from your CMakeLists.txt, but CDT requires it. Do not select Makefile project here!
- 对于项目类型,选择可执行文件。您还可以选择共享库或静态库,这并不重要,这些信息来自您的CMakeLists。txt,但CDT要求它。不要在这里选择Makefile项目!
- Finish project creation.
- 完成项目创建。
- 打开新的C/ c++项目向导("File" => " new " => "C项目"或"File" => " new " => " c++项目")。确保项目的位置指向您的项目类型的签出文件的根目录,选择可执行文件。您还可以选择共享库或静态库,这并不重要,这些信息来自您的CMakeLists。txt,但CDT要求它。不要在这里选择Makefile项目!完成项目创建。
- Open the "Project Properties" dialog.
- Select the "C/C++ Build" node and the "Builder Settings" tab and make sure Generate Makefiles automatically is checked.
- 选择“C/ c++构建”节点和“Builder设置”选项卡,并确保自动生成makefile。
- Select the "Tool Chain Editor" node and set "CMake Make Builder" as the current builder.
- 选择“工具链编辑器”节点,并将“CMake Make Builder”设置为当前构建器。
- If your top level CMakeLists.txt does not reside in the root directory of your checked out files, select the "C/C++ General" "Path and Symbols" node and the "Source Location" tab. Then adjust the source folder to point to the directory containing your CMakeLists.txt file. This will tell the CDT indexer to scan the header files in your project.
- 如果你的*CMakeLists。txt不会驻留在您的签出文件的根目录中,选择“C/ c++通用”“路径和符号”节点和“源位置”选项卡。然后调整源文件夹,指向包含CMakeLists的目录。txt文件。这将告诉CDT索引器扫描项目中的头文件。
- 打开“项目属性”对话框。选择“C/ c++构建”节点和“Builder设置”选项卡,并确保自动生成makefile。选择“工具链编辑器”节点,并将“CMake Make Builder”设置为当前构建器。如果你的*CMakeLists。txt不会驻留在您的签出文件的根目录中,选择“C/ c++通用”“路径和符号”节点和“源位置”选项卡。然后调整源文件夹,指向包含CMakeLists的目录。txt文件。这将告诉CDT索引器扫描项目中的头文件。
- Pro Tip: Add a CMakeLists.txt file in the root directory of your checked out files, if you miss the Binaries or Archives folder in the C/C++ Projects View. Build the project. This will invoke cmake to generate the build scripts, if necessary, and then will invoke make.
- 专业提示:添加一个CMakeLists。txt文件在您的签出文件的根目录中,如果您错过了C/ c++项目视图中的二进制文件或档案夹。构建项目。这将调用cmake来生成构建脚本,如果有必要的话,然后调用make。
Do not try to import an Eclipse project that you created manually using cmake -G Eclipse CDT4 - Unix Makefiles, as that will put you on the classic Makefile project route!
不要试图导入您使用cmake - g Eclipse CDT4 - Unix Makefile手工创建的Eclipse项目,这将使您在经典的Makefile项目路径上获得成功!
The best thing about this plugin is that it can use the cmake exported compiler options to index your project.
这个插件最好的地方是它可以使用cmake导出的编译器选项来索引您的项目。
- Open the "Project Properties" dialog.
- Select the "C/C++ General" node and the "Preprocessor Includes Paths, Macros etc." tab. Select "CMAKE_EXPORT_COMPILE_COMMANDS Parser" and move it to the top of the list.
- 选择“C/ c++通用”节点,“预处理器包括路径、宏等”选项卡。选择“CMAKE_EXPORT_COMPILE_COMMANDS解析器”并将其移到列表的顶部。
- Hit "OK" to close the dialog. Make sure to trigger one build now and recreate the index.
- 点击“确定”关闭对话框。确保现在触发一个构建并重新创建索引。
- 打开“项目属性”对话框。选择“C/ c++通用”节点,“预处理器包括路径、宏等”选项卡。选择“CMAKE_EXPORT_COMPILE_COMMANDS解析器”并将其移到列表的顶部。点击“确定”关闭对话框。确保现在触发一个构建并重新创建索引。
This fixed all the nasty indexer problems that were annoying me when I only used "CDT GCC Build-In Compiler Settings" and added stuff like "-std=c++14" to "Command to get the compiler specs".
当我只使用“CDT GCC内置编译器设置”和添加诸如“-std=c++14”到“命令获取编译器规范”之类的东西时,这些烦人的indexer问题就被解决了。
#3
3
Using CMAKE in Eclipse Makefile project(on win):
在Eclipse Makefile项目(win)中使用CMAKE:
1) create new "Makefile Project with Existing Code"
1)创建新的“Makefile项目与现有代码”
2) modify builder settings(Project Properties->C/C++ Build->Builder Settings):
2)修改生成器设置(项目属性->C/ c++ Build-> builder设置):
-
Build command: cmd /c "mkdir ${PWD} & cd /D ${PWD} && ${CMAKE} -G "Unix Makefiles" ${ProjDirPath} && make"
Build command: cmd /c "mkdir ${PWD} & cd /D ${CMAKE} -G "Unix makefile " ${ProjDirPath} && make"
-
Build directory: ${workspace_loc:/IoT_SDK}/build/${ConfigName}
构建目录:$ { workspace_loc:/ IoT_SDK } /构建/ $ { ConfigName }
That's all!
这是所有!
#4
1
In addition to accepted answer you should specify eclipse version.
除了接受的答案之外,您还应该指定eclipse版本。
Eclipse Luna (4.4):
Eclipse卢娜(4.4):
cmake -G"Eclipse CDT4 - Unix Makefiles" -D_ECLIPSE_VERSION=4.4 ../../src/Planner
Eclipse Kepler (4.3):
Eclipse开普勒(4.3):
cmake -G"Eclipse CDT4 - Unix Makefiles" -D_ECLIPSE_VERSION=4.3 ../../src/Planner
#5
1
Another completely different method.
另一个完全不同的方法。
-
Manually create an empty Eclipse project.
手动创建一个空的Eclipse项目。
-
Link source directory via Project Properties -> C/C++ General -> Paths and Symbols -> Source Location.
链接源目录通过项目属性-> C/ c++通用->路径和符号->源位置。
-
In the Debug and Release build directories create 'Make Targets' (using the 'Make Targets View'). Leave 'Make Target' field empty and set the 'command' field to
cmake -G "Unix Makefiles" <path/to/the/sources>
.在Debug和Release构建目录中创建“Make target”(使用“Make target View”)。离开“使目标”字段为空,并将“命令”字段设置为cmake -G“Unix makefile” <路径 to 源> 。
-
When you double-click on the 'Make Target' that you've created, it should trigger cmake invocation inside the Debug/Release dirs.
当您双击创建的“Make Target”时,应该在Debug/Release dirs中触发cmake调用。
-
In 'Project Properties -> C/C++ Build' disable built-in makefile generator.
在'项目属性-> C/ c++构建'禁用内置makefile生成器。
Now normal build should work. It will also pick up any changes in the CMakeLists.txt files (to the extent that CMake can).
现在正常的构建应该工作。它还将在CMakeLists中获得任何更改。txt文件(到CMake可以的程度)。
Maybe a more detailed description: https://*.com/a/38140914/4742108
也许是更详细的描述:https://*.com/a/38140914/4742108。