So I have a scenario where this guy’s question might apply. He’s looking to pack resources in with a .lib file, but that simply won’t work, as the file format doesn’t allow for it.
Thing is, my .lib is compiled in the same build sequence as the application it’s supposed to be pulled into, so perhaps I have a little more leeway. A couple things I’ve discovered:
- It doesn’t matter if you completely hose the syntax inside of one of a .rc file’s TEXTINCLUDE sections. Failures in there will not propagate out and indicate a build failure; your app will compile fine, but you won’t have any resources.
- Similarly, if you mess up the path to a .rc file you’d like to include, again, build errors won’t propagate out; you’ll just be missing the resources from that file.
Both of these mean that Roger Lipscombe’s 3rd solution, and jeff_t’s elucidation of that approach are very error prone. Even if you get it to work, it’ll likely take you a while to get it right, and you won’t know until you inspect the contents of of your resulting .DLL or .EXE module to see if the resources you’re looking for made it in. Maybe you can do that in a post-build step, but now we’re layering on more complexity, so we look somewhere else.
To take a different tact, you could add the path to your .res file to your main project’s linker options’ additional include directories, and then add your .res file to your inputs for that linker instance. In the past, I’ve found that approach to be error prone; if you have a bunch of project configurations, you need to make sure that that’s applied across all of them. That’s an additional step, which is an additional opportunity for error, and that particular error has bit me many times in the past. So we look somewhere else.
Another approach might be to try using #pragma comment(lib, “library.res”) and #pragma comment(linker, “/INCLUDE:path/to/library/”), surrounded by an IFDEF guard, in one of the headers that gets pulled into your main project. Except while the above approach works great with your .lib file, and while you can put .lib and .res files next to each other under inputs in your project’s linker settings, the above approach won’t work with your .res file. You get another silent error.
There’s really no good solution to pulling in .res files; they don’t have semantic parity with the same features and mechanisms that can pull in .lib files, despite some superficial similarities in their linking semantics. And everything that doesn’t work is a silent failure, until your program fails to find a resource at run time.