[CMake] link static lib to dll

Micha Renner Micha.Renner at t-online.de
Wed Feb 10 01:12:35 EST 2010


Am Dienstag, den 09.02.2010, 11:34 +0100 schrieb Michael Wild:
> On 9. Feb, 2010, at 11:05 , Micha Renner wrote:
> 
> > A DLL-library is linked to static library. 
> > The structure of the project is this:
> > 
> > main-project 
> > 	+--------- Project STATIC
> > 	|
> > 	+--------- Project DLL
> > 
> > This works very well.
> > But if I include the following export part to the project of the DLL...
> > 
> > INSTALL(TARGETS T-DLL EXPORT T-DLLExport 
> > 		RUNTIME DESTINATION dll		
> > 		LIBRARY DESTINATION lib
> > 	 	ARCHIVE DESTINATION lib)
> > INSTALL(EXPORT T-DLLExport DESTINATION lib/${T-DLL})
> > 
> > ... CMake generates the message: "CMake Error: INSTALL(EXPORT
> > "TLIBExport" ...) includes target "T-DLL" which requires target
> > "T-Static" that is not in the export set."
> > 
> > This is unexpected. I don't want export the static library because it is
> > already linked to the DLL and it is used only by the DLL.
> > 
> > Micha
> 
> But CMake can't know that somebody linking against the DLL won't need the static library. This is because the static library might contain additional symbols which are not used directly by any of the code in the DLL, and thus are not present in there. That's one of the most surprising facts of static linking...
This is true. Now, I understand the default behavior of CMake (Not bad,
CMake of course).  
> 
> The solution is to tell CMake explicitly which of the libraries are "in the link interface" and thus must be also exported using the LINK_INTERFACE_LIBRARIES target property of your DLL. Set it to the list of libraries which appear in the "link interface" of your library (i.e. NOT the static library you're talking about). But be careful, if you miss any of the real dependencies, all hell might break loose at any time, even far in the future...

Hopeless, I would have never found this solution.
Thank you very much.
Micha





More information about the CMake mailing list