Partners: KDAB Whole Tomato Software CppDepend

16 May 2012

FreeGLUT 2.8 linking problems

update: works with freeGLUT 2.8.1 as well
From some time I've been having some frustrating linker errors in my VS C++ 2010 Express projects when linking against newest freeGlut 2.8 - static.
I downloaded the library from http://freeglut.sourceforge.net/ and rebuilt it as a static_release version using Visual Studio Express 2010
Then, when linking in my OpenGL app I got:
freeglut_static.lib(freeglut_main.obj) : 
  warning LNK4099: PDB 'vc100.pdb' was not found with 
  'freeglut_static.lib(freeglut_main.obj)' or at 'vc100.pdb'; 
  linking object as if no debug info
freeglut_static.lib(freeglut_callbacks.obj) : 
  warning LNK4099: PDB 'vc100.pdb' was not found with 
  'freeglut_static.lib(freeglut_callbacks.obj)' or at 'vc100.pdb';
  linking object as if no debug info
freeglut_static.lib(freeglut_state.obj) : 
  warning LNK4099: PDB 'vc100.pdb' was not found with 
  'freeglut_static.lib(freeglut_state.obj)' or at 'vc100.pdb'; 
  linking object as if no debug info
...
...
Why is that?
Of course project is working fine... those are only warnings... but there are to many of them and it is quite inelegant!
First thing: The Lib was built with debug info and VS cannot find it (those pdb files) when used in second project. When you build a lib on your machine then the warnings will not be reported - because you have all pdb files and VS knows their location. But when you build the lib and then use it on some other machine the problem will occur.
Solution: We have to disable debug info in freeglut. Simply go to:
Properties -> C/C++ -> General and set Debug Information Format to C7 compatible (/Z7) or leave empty space there.
The first option will produce debug info but it will store it in the OBJ file. The second option will skip the debug info generation. This is good for release version since it will compile much faster and the output file will be smaller. I also disabled whole program optimization in the Optimization section as well. When I compiled library again and linked with my project... I got nice info:
1>  myProject.vcxproj -> myProject.exe
======== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========
Moreover now freeglut_static.lib is only 532 KB instead of 1612 KB :)
More info:
If you create a library from objects that were compiled using this option (/Zi or /ZI), the associated .pdb file must be available when the library is linked to a program. Thus, if you distribute the library, you must distribute the PDB.

Get my free ebook about C++17!

More than 50 pages about the new Language Standard.

C++17 in detail, by Bartlomiej Filipek

© 2017, Bartlomiej Filipek, Blogger platform
Any opinions expressed herein are in no way representative of those of my employers.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.