[osg-users] [build] Proper CMAKE settings for ZLIB, bogus "optimized.lib" in link

Jan Ciger jan.ciger at gmail.com
Wed Nov 2 15:01:33 PDT 2016


On 02/11/16 22:05, Andrew Cunningham wrote:
> Hi,
> I am trying to build OSG 3.4.0 on Windows/Visual Studio 2015 using CMake to generate the projects.
>  Everything works pretty well except the confusing settings for ZLIB_LIBRARY, ZLIB_LIBRARY_DEBUG,ZLIB_LIBRARY_RELEASE. Why 3 settings ?
> I included paths to Debug and Release builds of ZLib,  in the ZLIB_LIBRARY_DEBUG and ZLIB_LIBRARY_RELEASE respectively and left ZLIB_LIBRARY blank. 
> Although the DEBUG build is ok , my RELEASE builds ended up with library references to non-existent "optimized.lib" and "debug.lib"  as well as duplicating the debug and release versions of the zlib libraries.
> For example, this is pasted from the VS linker settings for and OSG project.
> ....-
> optimized.lib
> D:\OSG\3rdParty\build\lib\Release\zlib.lib
> debug.lib
> D:\OSG\3rdParty\build\lib\Debug\zlibd.lib
> ....
> Andrew

That is completely normal. Visual Studio uses different C/C++ runtimes
for Debug and Release configurations and if you mix libraries compiled
against different C/C++ runtimes you will get memory corruption and
weird crashes at runtime. So it is an extremely bad idea to mix them
unless you know what you are doing (and probably even then).

Why there are 3 variables - I don't remember exactly the OSG's setup,
but typically:

CMake variables ("advanced" in CMake parlance)

* ZLIB_LIBRARY would contain something a value calculated by the script
from the two variables above like this:

The "debug" and "optimized" keywords denote which runtime is the library
meant for. This is the variable you would then normally use when
configuring linking for the target (exe or library) in the CMake script.

This is Window/Visual Studio specific pain in the backside, no other
platform that I know of has this problem with requiring separate
libraries for debugging/optimized build configurations.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 173 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20161102/6fe73d1d/attachment-0003.pgp>

More information about the osg-users mailing list