开发者

Linking a resource file with the application?

I'm using the MinGW compiler suite on Windows, using Eclipse. How do I link a resource file (.开发者_运维问答rc) with my application so things like version number, icon information, etc. are included inside the executable? I tried playing around with windres, but I'm not sure where to include in the build process.

Secondarily, is there a way to have Eclipse auto-increment the version number on each (re)-build?


I'm not sure if this is the best way of going about, but this is what I did to accomplish this within the Eclipse environment.

1. Creating the resource
Create a folder called "Resources" or something like this that will hold resource information. A few files will be created in this process, so it is best for the resource to have its own folder. Create your .rc resource file within this folder. Visual Studio comes with a tool that helps with the creation of a resource file. With the file open in Visual Studio, right click the folder icon of the resource and then select "Add Resource." Select "Version" then click "New." Change what you need and then click save within Visual Studio. This will also create a resource.h file in the same directory that has many helpful definitions. Close out of Visual Studio now. If you know how to create the resource manually then you can skip opening it in Visual Studio. I just find it helpful to have the resource generated for me this way.

2. Compiling the resource
Now that your resource has been created, go to your project properties in Eclipse (right click your project and select properties). Go to "C/C++ Build->Settings." In the "Build Steps" enter "windres ..\src\Resources\MyResource.rc ..\src\Resources\MyResource.o" for a pre build event. Change the directory to where your resource is located. The directory tree is referencing the output directory here. What this will do is compile the resource to an object file before a build.

3. Linking the resource
Now the object file will need to be linked. In the same "C/C++ Build->Settings" window in the properties, select the "Tool Settings" tab. Click on the "Miscellaneous" folder icon under "MinGW C++ Linker" option. Click the add icon under "Other objects" list on the bottom right. Enter the path "src\Resources\MyResource.o" here and click ok. The path references the project directory here.

Note that the IDE will not recognize changes to the .rc file as a code change. If you make changes to this file without changing any code then you will need to clean and rebuild the project for the change to take effect in the resulting binary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜