Friday, December 21, 2007

Building GDAL 1.4.4 using Visual Studio 2008

Or this post could also be called - fixing C3136 error during GDAL build.

I have the release to market (RTM) edition of Visual Studio 2008 on my machine and decided to try building GDAL 1.4.4 binaries under Visual Studio 2008 (Professional Edition). Unfortunately when I first tried it, I got the following error:

error C3163: '_vsnprintf': attributes inconsistent with previous declaration

So how do you fix it?

I think the issue is that _vsnprintf is now being declared in some native header of Visual Studio. This results in a clash with any product that might be defining the function in its code. (And I think there might be a ton of projects that might be defining the function and hence will definitely cause a head-ache for many developers out there).

To fix it: Look for _vsnprintf in your code. If you see a line similar to

#define vsnprintf _vsnprintf

Then comment it out and you should be back in business. (For the GDAL source - that offending piece of code was found in port\cpl_config.h)

note: (update 12.25.2007) GDAL version 1.5.0 builds fine with Visual Studio 2008. All you need to do is set the correct MSVC_VER number in the nmake.opt file

1 comment:

Mikhail Oleynik said...

Thank you for solution!