[Spice-devel] [vdagent-win V2 1/6] Fix building with Visual Studio (inttypes.h)

Uri Lublin uril at redhat.com
Tue Mar 25 10:27:18 PDT 2014


On 03/25/2014 11:11 AM, Christophe Fergeau wrote:
> On Mon, Mar 24, 2014 at 07:02:38PM +0200, Uri Lublin wrote:
>> As a followup of commit 462295d9f84658aa7.
>>
>> Building with Visual Studio, fails as there is no inttypes.h file:
>>    vdagent\file_xfer.cpp(21) : fatal error C1083: Cannot open
>>    include file: 'inttypes.h': No such file or directory
>>
>> This commit prevents including inttypes.h when building with Visual Studio,
>> and defines PRIu64 that is defined in inttypes.h for mingw compiler.
> Visual Studio 2013 apparently has inttypes.h and PRIu64 so this may trigger
> a warning about redefining PRIu64 (? (?) Maybe we'd be better off just
> using http://code.google.com/p/msinttypes/source/browse/ with VC?

Hi Christophe,

Thanks for checking it out.
I didn't know that Visual Studio 2013 does have inttypes.h

I think that even when building with Visual Studio 2013, there should
be no problem with this patch as inttypes.h will not be included, so
PRIu64 should not be already defined (and redefined by this patch).

Currently we are only using a single definition.
I don't think we should add the 2 files you in the link above, but I'm not
against that either.
Optionally, I can move this patch to an .h file, to be reused by other 
c-files
if needed.

Thanks,
     Uri.

>
>> ---
>>   vdagent/file_xfer.cpp | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
>> index e402eb2..d1459c1 100644
>> --- a/vdagent/file_xfer.cpp
>> +++ b/vdagent/file_xfer.cpp
>> @@ -18,7 +18,14 @@
>>   #include <shlobj.h>
>>   #define __STDC_FORMAT_MACROS
>>   #define __USE_MINGW_ANSI_STDIO 1
>> +
>> +// compiler specific definitions
>> +#ifdef _MSC_VER // compiling with Visual Studio
>> +#define PRIu64 "I64u"
>> +#else // compiling with mingw
>>   #include <inttypes.h>
>> +#endif // compiler specific definitions
>> +
>>   #include <stdio.h>
>>   #include "file_xfer.h"
>>   #include "as_user.h"
>> -- 
>> 1.8.5.3
>>


More information about the Spice-devel mailing list