C++ cmake 和 netbeans 可以玩吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6608569/
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
can cmake and netbeans play nice?
提问by Martin Kristiansen
I'm working on a big project, some might say awesome.
我正在做一个大项目,有人可能会说很棒。
The project is being developed in c++ with cmake and netbeans. Everything is working fine except from the fact that every time I do updates to the project, add or remove source files, netbeans runs cmake and adds a new project to 'projects' list. This is somewhat annoying since i tend to do this alot.
该项目正在使用 cmake 和 netbeans 用 c++ 开发。一切正常,除了每次我更新项目、添加或删除源文件时,netbeans 都会运行 cmake 并将一个新项目添加到“项目”列表中。这有点烦人,因为我经常这样做。
Is there a smart way to make sure netbeans does not create new projects every time a sub directory is added?
有没有一种聪明的方法来确保每次添加子目录时 netbeans 都不会创建新项目?
采纳答案by Alba Mendez
Good news!
好消息!
As of NetBeans 6.8, CMake is handled gracefully, just like any other configurescript:
从 NetBeans 6.8 开始,CMake 被优雅地处理,就像任何其他configure脚本一样:
- Make a new "C/C++ Application from existing sources".
- Specify the directory of the project (where
CMakeLists.txtresides). - In the "Select configuration mode", select "Automatic".
- 从现有源创建一个新的“C/C++ 应用程序”。
- 指定项目的目录(
CMakeLists.txt所在的位置)。 - 在“选择配置模式”中,选择“自动”。
And NetBeans will run cmaketo build the Makefilewhen it's necessary
(or when you click "Reconfigure project").
NetBeans 将在必要时运行cmake以构建Makefile它
(或当您单击“重新配置项目”时)。
See the original thread on the NetBeans forumsfor more info.
有关详细信息,请参阅NetBeans 论坛上的原始主题。
回答by ollo
CMake-bases projects work perfect with NetBeans.
基于 CMake 的项目与 NetBeans 完美配合。
Variation to jmendethanswer:
jmendeth答案的变化:
- Create a new
C/C++ Project with Existing Sources - Set the projects path (= directory of main
CMakeLists.txt) - At
Select Configuration modesetCustom - Click
Next - Select
Run Configure Script in Subfolder(the default folder isbuild) - If you don't have further settings, click
Nextuntil you can click finish - Click
Finish, Cmake will run and build your project
- 创建一个新的
C/C++ Project with Existing Sources - 设置项目路径(= main 目录
CMakeLists.txt) - 在
Select Configuration mode集合Custom - 点击
Next - 选择
Run Configure Script in Subfolder(默认文件夹是build) - 如果您没有进一步的设置,请单击
Next直到您可以单击完成 - 单击
Finish,Cmake 将运行并构建您的项目
This way is a bit longer then the automatic one, however in practice it's just setting of two ticks.
这种方式比自动方式稍长,但实际上它只是设置两个刻度。
The advantage and hence the reason for the additional expenses: CMake will now put all it's local cache filesin a subfolder(build) and keep them separate at one place - not mixing them with your other project stuff.
优势以及额外费用的原因:CMake 现在将所有本地缓存文件放在一个子文件夹( build) 中,并将它们分开放在一个地方 - 不会将它们与您的其他项目内容混合。
This keeps a clean project structure, since those files are just for your project and created by each configure run.
这保持了干净的项目结构,因为这些文件仅用于您的项目并由每次配置运行创建。
And as an extra: If you have to delete the CMake cache manually - this happens sometimes - there's one single directory where everything is in.
作为额外的:如果您必须手动删除 CMake 缓存 - 有时会发生这种情况 - 有一个目录,所有内容都在其中。
Side note:
边注:
Since NetBeans 8.0there's syntax coloringfor all CMake files.
从NetBeans 8.0 开始,所有 CMake 文件都有语法着色。
回答by berardino
I was getting this error : "failed to start cmake: No such file or directory"
我收到此错误:“无法启动 cmake:没有这样的文件或目录”
I had to NetBeans -> Preferences -> C/C++ (Build Tools) -> set the CMake Command to /opt/local/bin/cmake .
我不得不 NetBeans -> Preferences -> C/C++ (Build Tools) -> 将 CMake 命令设置为 /opt/local/bin/cmake 。
回答by JoniPichoni
I am using Cmake, netbeans and SVN with a large c++ project, with no problem.
我在一个大型 C++ 项目中使用 Cmake、netbeans 和 SVN,没有问题。
I usually configure the project with the option "c++ with existing sources" and select the makefile genereted by cmake so netbeans don't know which make tool I am using. Then select only the folders with the sources you need to work on.
我通常使用选项“c++ with existing sources”配置项目,并选择由 cmake 生成的 makefile,因此 netbeans 不知道我使用的是哪个 make 工具。然后仅选择包含您需要处理的源的文件夹。
Every time you update the sources you must update your Makefile (and the Netbeans Project will update the sources too) running cmake so you can do it manually or just in the build command of the project: "cmake .. && make" (thats tricky but it works fine). Hope to be useful.
每次更新源代码时,您都必须更新 Makefile(并且 Netbeans 项目也将更新源代码)运行 cmake,以便您可以手动或仅在项目的构建命令中执行此操作:“cmake .. && make”(这很棘手但它工作正常)。希望有用。

