如何编译/构建/执行 C++热尼项目?
我真的没想到会这么难。 Geany 显然具有创建项目、向项目添加文件、编译各个文件的能力,但即使在谷歌搜索之后我也找不到如何构建和执行项目的清晰描述......这很烦人,因为我真的喜欢 Geany 的简洁性及其干净、整洁的工作空间,但这可能会破坏交易。
I really didn't think it would be this difficult. Geany clearly has the ability to create projects, add files to the projects, compile the individual files, but then even after googling it I could not find a clear description of how to build and execute the project... It's pretty annoying because I really like the simplicity of Geany and its clean, uncluttered workspace, but this could be a deal breaker.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Geany 不编译项目。您可以使用 makefile 来达到相同的目的;但是,您必须手动进行或使用可以找出依赖关系的外部命令。 Geany 的“make”命令将默认使用名为“makefile”的 make 文件,因此您只需为 make 文件指定该名称即可,一切都应该很好。
示例取自此处。您还可以在该页面上找到更多详细信息。
Geany doesn't compile projects. You can use a makefile to serve the same purpose; however, you have to make it manually or use an external command that can figure out dependencies. Geany's "make" command will use the make file called "makefile" by default, so you can simply give your make file that name and all should be well.
Example taken from here. You can find more detailed information on that page as well.
要构建项目,只需打开项目的文件,然后在“构建”菜单中选择“生成”(shift+F9)。
用于执行菜单“构建并执行”(F5)。
如果项目未使用 make 进行编译(在 Linux 上通常如此),您还必须在菜单“项目”条目“属性”中编辑项目的属性。
如果你想要详细信息,你也可以阅读手册,与谷歌搜索相比,它似乎很愚蠢,但对我来说看起来很清楚......只需按 F1 键即可。
To build project just open a file of the project, then choose Make in the Build menu (shift+F9).
For executing menu Build and Execute (F5).
If the project does not compile using make (as it usually does on Linux), you will also have to edit properties of the project in the menu Project entry Properties.
If you want details you could also read the manual, it could seems dumb compared to googling, but it looks quite clear to me... Just hit F1 key.
根据this,按F8编译,按F5运行项目。不过,您首先必须设置编译器,如文章中所述。
According to this, hit F8 to compile and F5 to run the project. You first have to setup the compiler though, as mentioned in the article.
Geany 使用外部命令构建项目。这是灵活的,并且允许 IDE 与语言无关,从而能够构建大型且异构的项目。
对于 C++,创建基本的 Makefile 非常简单(比上面的示例简单得多)。假设您的项目构建了一个名为“my_program”的程序,由文件 my_program.cpp 和 bar.cpp 组成,并链接到 foo 库。你所需要的只是这个:
将其以名称“Makefile”保存在源的同一目录中。现在您必须正确创建 Geany 项目,表明基目录是代码所在的位置(并且Makefile)被存储。
就是这样!现在,您可以使用按键(shift+F9)来编译程序。如果也使用按键运行它,只需在 Geany 的项目属性中输入您的程序名称(示例中为 my_program)。
请注意,源文件之一与目标二进制文件具有相同的名称非常重要,否则您无法使用 Make 的隐式规则,这会使 Makefile 有点复杂。
Geany builds projects using external commands. This is flexible and allows the IDE to be language-agnostic, thus being able to build large and heterogeneous projects.
Regarding C++, it's very simple to create a basic Makefile (much simpler than the example above). Supose your project builds a program called "my_program", consists of the files my_program.cpp and bar.cpp, and links with the foo library. All you need is this:
Save this with the name "Makefile" in the same directory of the sources.Now you have to create the Geany project proper, indicating that the base directory is where the code (and Makefile) are stored.
That's it! you can now compile you program with a keypress (shift+F9). For also running it with a key just enter your program name (my_program in the example) in the Geany's project properties.
Note that it's important that one of your source files has the same name as the target binary, otherwise you cannot user Make's implicit rules, wich complicates the Makefile a bit.
使用 Geany 的 F 键编译多文件 C++ 项目需要首先在 Geany 中设置 Makefile 和相应的设置(如前面的答案所述);完成此类设置后,Geany 的构建下拉菜单中的 F 键对于该特定的多文件项目变得有用。
但是,如果您只是想快速编译多文件 C++ 项目,而无需设置 Makefile 以及 Geany 的设置,请使用 Geany 底部的终端键入编译多文件项目的命令行指令
:然后可以使用以下命令执行您的可执行文件:(
请注意,上述内容适用于 Linux 上的 Geany;我尚未在其他操作系统上测试上述命令。)
Compiling a multi-file C++ project using Geany's F-keys requires that you first setup a Makefile and the corresponding settings in Geany (as described in previous answers); after such setup is completed the F-keys in Geany's Build drop-down menu become useful for that particular multi-file project.
If however you just want to quickly compile a multi-file C++ project without having to setup a Makefile as well as Geany's settings, use the terminal at the bottom of Geany to type the command-line instruction for compiling a multi-file project:
You can then execute your executable with:
(Note that the above applies to Geany on Linux; I have not tested the above commands on other operating systems.)
假设您正确设置了路径(右键单击
我的电脑>属性>高级系统设置>环境变量
,只需谷歌搜索下一步做什么)和Mingw正确,单击“设置构建菜单”命令”并输入以下内容。包括“”。这对我有用,如果您在尝试构建时(编译后)出现错误,说明某些权限问题,即 Windows UAC 的 b/c 阻止 Geany 构建。您只需要以管理员身份运行 geany 即可解决此问题。
Assuming you set up your paths(right-click
my computer > properties > advanced system settings > environment variables
, just google search what to do next) and Mingw correctly, click on "set build menu commands" and enter the following. including the "".this is what worked for me, if you get an error when trying to build (after you compiled) that says something about some permissions issue, that is b/c of windows UAC is blocking Geany from building. You just need to run geany as admin to resolve this.