Reputation: 2315
I'm trying to build an application developed in VS 2010 with VS2017. When I'm building the application I'm getting the following error:
error: : Macro definition of snprintf conflicts with Standard Library function declaration
I tried to solve this issue like as here. But It doesn't work in my case.
I'm using windows 10 with VS2017 community 15.8.2.
Upvotes: 5
Views: 9968
Reputation: 287
The error message is supposed to helpfully tell you what file has the offending #define. In my case, it was wrong. CMAKE was adding a header (my_config.h in my case) that didn't directly show up by tracing the error code. And doing a solution wide search for #define snprintf _snprintf yielded zero results.
How I found the offending #define:
Attempt to build.
Get error message: #error: Macro definition of snprintf conflicts with Standard Library function declaration (compiling source file D:\PathToFile\libmysql.c). libmysql.c has no such definition, nor do any of the headers it includes.
Double-click the error message. This opens stdio.h in a new tab, at the line where the error is generated (line 1914 in my case).
1906 #if defined snprintf
1907 // This definition of snprintf will generate "warning C4005: 'snprintf': macro
1908 // redefinition" with a subsequent line indicating where the previous definition
1909 // of snprintf was. This makes it easier to find where snprintf was defined.
1910 #pragma warning(push, 1)
1911 #pragma warning(1: 4005) // macro redefinition
1912 #define snprintf Do not define snprintf as a macro
1913 #pragma warning(pop)
1914 #error Macro definition of snprintf conflicts with Standard Library function declaration
1915 #endif
Hover over the word snprintf where it checks for the define (line 1906 in my case). Intellisense will show you |>| #define snprintf _snprintf in a tooltip.
Right-click the word snprintf (not the tooltip) and click either Peek Definition or Go To Definition. This pops up the offending #define which you can now delete or modify as needed.
493 #define ssize_t SSIZE_T
494 #define strcasecmp _stricmp
495 #define strncasecmp _strnicmp
496 #define snprintf _snprintf // <-- Offending line.
497 #define strtok_r strtok_s
498 #define strtoll _strtoi64
499 #define strtoull _strtoui64
In my case, the offending line was 496, which I simply deleted.
Go back to stdio.h and hover over the snprintf word and it should no longer give you a tooltip as it's not defined (mine also changed from purple to white).
Upvotes: 5
Reputation: 15200
As the error in your question shows, you have a macro definition for snprintf
that is no longer compatible with your current version.
So you need to look for the following:
#define snprintf _snprintf
You can either remove it or if you need to also compile your code with Visual Studio 2010 you can add the following condition:
#if _MSC_VER < 1700
#define snprintf _snprintf
#endif
Upvotes: 9