[Interest] What is the right way of creating a static lib that has qml resources with cmake?

Ulf Hermann ulf.hermann at qt.io
Thu Jan 12 20:39:27 CET 2023


> Yes, there is. There's -Wl,--whole-archive for the Unix linkers. This should
> solve the problem for everyone except MSVC users.

That option is not very attractive because:

a, as you state yourself, it doesn't work on MSVC.

b, it only works at the last link step, when the library is linked into 
some application or dynamically linked binary. That step might not be 
under our control and it might involve a lot of other objects that we 
actually want the linker to remove. I know, you can selectively apply 
--whole-archive to only part of the linker line, but by that time, the 
plugin we're looking for might be linked into some other .a file 
together with more stuff.

I haven't actually invented the plugin import mechanism, but AFAIU, it 
allows us to specify plugins, and nothing else, as the stuff to be kept 
around even if it's not referenced. QML modules piggy-back on that by 
creating small plugins that do nothing but hold a reference to the type 
registration function.

Ulf


More information about the Interest mailing list