Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexer.hpp(1363) '_snprintf': is not a member | Visualstudio 2017 #1437

Closed
kenkit opened this issue Jan 15, 2019 · 11 comments
Closed

lexer.hpp(1363) '_snprintf': is not a member | Visualstudio 2017 #1437

kenkit opened this issue Jan 15, 2019 · 11 comments
Labels
platform: visual studio related to MSVC solution: duplicate the issue is a duplicate; refer to the linked issue instead solution: invalid the issue is not related to the library

Comments

@kenkit
Copy link

kenkit commented Jan 15, 2019

Hi, I upgraded my project to the latest json, but I can't get past this error.
I use cmake as my build system, also tried setting stdc++11 but nothing worked

D:\Programming\bak\google_driver\json\include\nlohmann/detail/input/lexer.hpp(1363): error C2039: _snprintf: is not a member of std

@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

more after removing std:: from the first file

"D:\Programming\bak\google_driver\build\AnimePlugin_Test.vcxproj" (default target) (1) ->
"D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj" (default target) (3) ->
(ClCompile target) ->
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(375): error C2039: '_snprintf': i
s not a member of 'std' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(381): error C2039: '_snprintf': i
s not a member of 'std' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(419): error C2039: '_snprintf': i
s not a member of 'std' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(500): error C2039: '_snprintf': i
s not a member of 'std' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]

@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

after patching all snprintf


"D:\Programming\bak\google_driver\build\AnimePlugin_Test.vcxproj" (default target) (1) ->
"D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj" (default target) (3) ->
(ClCompile target) ->
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(540): error C2065: 'is_same': und
eclared identifier [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(540): error C2061: syntax error:
identifier 'value' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(541): error C2988: unrecognizable
 template declaration/definition [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(541): error C2059: syntax error:
',' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(544): error C2334: unexpected tok
en(s) preceding '{'; skipping apparent function body [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxpr
oj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(587): error C2988: unrecognizable
 template declaration/definition [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(587): error C2059: syntax error:
'if' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(588): error C2334: unexpected tok
en(s) preceding '{'; skipping apparent function body [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxpr
oj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(602): error C2061: syntax error:
identifier 'x' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(602): error C4430: missing type s
pecifier - int assumed. Note: C++ does not support default-int [D:\Programming\bak\google_driver\build\UtilitiesPlugin_
TEST.vcxproj]
  D:\Programming\bak\google_driver\json\include\nlohmann/detail/output/serializer.hpp(605): error C2144: syntax error:
'void' should be preceded by ';' [D:\Programming\bak\google_driver\build\UtilitiesPlugin_TEST.vcxproj]

@gregmarr
Copy link
Contributor

gregmarr commented Jan 15, 2019

Some header that you are including before json.hpp is doing a

#define snprintf _snprintf

You can either change the include order, or put this before including json.hpp

#undef snprintf

@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

ooh, nice. Let me try. Was actually downgrading back to v3.0.0

@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

"D:\Programming\bak\google_driver\build\AnimePlugin_Test.vcxproj" (default target) (1) ->
(ClCompile target) ->
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro def
inition of snprintf conflicts with Standard Library function declaration [D:\Programming\bak\google_driver\build\AnimeP
lugin_Test.vcxproj]

    3 Warning(s)
    1 Error(s)

@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

let me try putting it first instead

@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

same problem

C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h(1933): warning C4005: 'snprintf': macro redefi
nition [D:\Programming\bak\google_driver\build\AnimePlugin_Test.vcxproj]
  d:\programming\bak\google_driver\anime\anime_manager.h(3): note: see previous definition of 'snprintf'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro defin
ition of snprintf conflicts with Standard Library function declaration [D:\Programming\bak\google_driver\build\AnimePlu
gin_Test.vcxproj]

I made json.hpp first in all my includes

@gregmarr
Copy link
Contributor

Looks like this header is defining it: d:\programming\bak\google_driver\anime\anime_manager.h

@nlohmann
Copy link
Owner

This seems to be a duplicate of #1408. We successfully compile the library with MSVC 2017, see https://ci.appveyor.com/project/nlohmann/json/builds/21611843/job/cyq14vhdxfa20e1v for instance.

@nlohmann nlohmann added the platform: visual studio related to MSVC label Jan 15, 2019
@kenkit
Copy link
Author

kenkit commented Jan 15, 2019

Yeah, darn. I had been messing with most of the files I forgot I defined it earlier in there.
Thanks now it builds perfectly

@kenkit kenkit closed this as completed Jan 15, 2019
@nlohmann nlohmann added solution: duplicate the issue is a duplicate; refer to the linked issue instead solution: invalid the issue is not related to the library labels Jan 15, 2019
@abellgithub
Copy link

Perhaps one could do (std::snprintf)(...) if it's a common thing for snprintf to get #define'd on windows. Yes, it shouldn't be necessary, but it's robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: visual studio related to MSVC solution: duplicate the issue is a duplicate; refer to the linked issue instead solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

4 participants