[英]Eclipse CDT build/run on file basis
In my scenario I have a C++ project in CDT Eclipse. 在我的场景中,我在CDT Eclipse中有一个C ++项目。 This projects however is rather a collection of individual (helper) programs than one complex application.
但是,该项目实际上是单个(帮助程序)程序的集合,而不是一个复杂的应用程序。 Consequently I want to be able to build and run them individually.
因此,我希望能够分别构建和运行它们。
My project structure is very simple and looks like: 我的项目结构非常简单,看起来像:
src/app1.cpp
src/app2.cpp
src/...
Note that I do not have common header files or libraries. 请注意,我没有通用的头文件或库。 However I want to be able to add programs to this project just by creating eg src/appx.cpp
但是我希望仅通过创建例如src / appx.cpp就可以向该项目添加程序
Ideally I want to have shortcuts for 理想情况下,我想为
Any suggestions on how to achieve this behaviour, if possible without additional plugins? 如果没有附加插件,是否有任何有关如何实现此行为的建议?
The straightforward way to succeed what you aim is to create a Makefile project with CDT and add a new target rule for each of your applications inside your Makefile . 接替你的目标是什么简单的方法是创建CDT一个Makefile项目,并添加一个新的目标规则为每个Makefile里的应用程序。 You can even use SCons or other build systems with a CDT Makefile project and obtain the same effect.
您甚至可以将SCons或其他构建系统与CDT Makefile项目一起使用,并获得相同的效果。
You can also trick the managed build to create executables instead of object files. 您还可以欺骗托管版本以创建可执行文件而不是目标文件。 Remove
-c
option from Other flags of C++ compiler settings inside project properties. 从项目属性内的C ++编译器设置的“ 其他”标志中删除
-c
选项。 This will produce a separate application file for each of your source files. 这将为您的每个源文件生成一个单独的应用程序文件。
Application files which are created inside the build directory will have the object file extension and they will not be executable. 在构建目录中创建的应用程序文件将具有目标文件扩展名,并且将无法执行。 To solve this, you can add a post build script in your project directory such as:
为了解决这个问题,您可以在项目目录中添加一个后构建脚本,例如:
postbuild.sh
for Linux: postbuild.sh
于Linux的postbuild.sh
:
chmod +x *.o
rename -v 's/\.o$//' *.o
or postbuild.bat
for Windows: 或Windows的
postbuild.bat
:
rename *.o *.exe
After adding ../postbuild.sh
or ../postbuild.bat
as a post build command in your build settings, you applications will be ready to run. 在构建设置中添加
../postbuild.sh
或../postbuild.bat
作为构建后命令之后,您的应用程序将可以运行。 Right click on any of these executable files and choose Debug As
or Run As
and a new Run configuration will be created. 右键单击任何这些可执行文件,然后选择“
Debug As
或Run As
,将创建一个新的“运行”配置。
Also you will have to stop the linker of the managed build to prevent errors. 另外,您还必须停止托管构建的链接器以防止错误。 This can be achieved with changing the linker command to
true
(Linux) or true.exe
(Windows, msys). 可以通过将链接器命令更改为
true
(Linux)或true.exe
(Windows,msys)来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.