VC++ resources in a static library

前端 未结 7 1957
天涯浪人
天涯浪人 2020-11-29 21:30

Is it possible to build resources into a static library and reuse them by simply linking with the library?

I\'m primarily thinking about the case where you call a fu

7条回答
  •  北海茫月
    2020-11-29 22:11

    As per Visual Studio 2010, the development tools from Microsoft apparently cannot properly handle compiled resource data inside static libraries at all.

    To distribute a compiled resource file (a .res file), you have two choices:

    1. Distribute the .res files separately, and instruct the client code to link against them;
    2. Use cvtres to merge several .res files into a single object (.obj) file, and provide it separately.

    Note that you can't lib in object files created with cvtres. If multiple object files are provided, lib complains as though as multiple .res files were given; if a single object file is provided, lib does not complain, but the linker simply ignores the embedded resource data in the lib file.

    It might be the case that there is a way to force the linker to read and link the libbed in resource data (with some command-line option, section manipulation and so on), since the resource data is indeed available in the library (as dumpbin reveals). So far, I haven't found a solution, and, unless one is willing to hack the development tools, anything better than this simple solution is probably not worth the effort.

    The only way to ship resource data in a static library (in this case, with a static library) is to distribute the resources separately and explicitly link them in the client code. Using cvtres can reduce the number of distributed resource files to one, if you have many of them.

提交回复
热议问题