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

npm install canvas fails: Macro definition of snprintf conflicts with Standard Library function declaration #605

Closed
neojhz opened this issue Aug 4, 2015 · 6 comments
Labels

Comments

@neojhz
Copy link

neojhz commented Aug 4, 2015

Hi,

I've installed VS2015 and I have a suspicion that this is due to this.

npm install canvas fails to build with errors:

:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925):
 warning C4005: 'snprintf': macro redefinition (compiling source file ..\src\Ca
nvasPattern.cc) [\node_modules\canvas
\build\canvas.vcxproj]
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925
  ): note: command-line arguments:  see previous definition of 'snprintf' (comp
  iling source file ..\src\CanvasPattern.cc)
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1927):
 fatal error C1189: #error:  Macro definition of snprintf conflicts with Standa
rd Library function declaration (compiling source file ..\src\CanvasPattern.cc)
 [\node_modules\canvas\build\canvas.v
cxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925):
 warning C4005: 'snprintf': macro redefinition (compiling source file ..\src\Ca
nvasGradient.cc) [...\node_modules\canva
s\build\canvas.vcxproj]
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925
  ): note: command-line arguments:  see previous definition of 'snprintf' (comp
  iling source file ..\src\CanvasGradient.cc)
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1927):
 fatal error C1189: #error:  Macro definition of snprintf conflicts with Standa
rd Library function declaration (compiling source file ..\src\CanvasGradient.cc
) [...\node_modules\canvas\build\canvas.
vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925):
 warning C4005: 'snprintf': macro redefinition (compiling source file ..\src\Ca
nvas.cc) [...\\node_modules\canvas\build\
canvas.vcxproj]
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925
  ): note: command-line arguments:  see previous definition of 'snprintf' (comp
  iling source file ..\src\Canvas.cc)
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1927):
 fatal error C1189: #error:  Macro definition of snprintf conflicts with Standa
rd Library function declaration (compiling source file ..\src\Canvas.cc) [...\\node_modules\canvas\build\canvas.vcxproj]
  color.cc
  Image.cc
  ImageData.cc
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925):
 warning C4005: 'snprintf': macro redefinition (compiling source file ..\src\co
lor.cc) [...\node_modules\canvas\build\c
anvas.vcxproj]
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925
  ): note: command-line arguments:  see previous definition of 'snprintf' (comp
  iling source file ..\src\color.cc)
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1927):
 fatal error C1189: #error:  Macro definition of snprintf conflicts with Standa
rd Library function declaration (compiling source file ..\src\color.cc) [...\node_modules\canvas\build\canvas.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925):
 warning C4005: 'snprintf': macro redefinition (compiling source file ..\src\Im
age.cc) [...\node_modules\canvas\build\c
anvas.vcxproj]
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1925
  ): note: command-line arguments:  see previous definition of 'snprintf' (comp
  iling source file ..\src\Image.cc)
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1927):
 fatal error C1189: #error:  Macro definition of snprintf conflicts with Standa
rd Library function declaration (compiling source file ..\src\Image.cc) [...\dominantcolor\node_modules\canvas\build\canvas.vcxproj]
  init.cc

I've seen this post

http://stackoverflow.com/questions/27754492/vs-2015-compiling-cocos2d-x-3-3-error-fatal-error-c1189-error-macro-definiti

but this requires source changes.

Or is there another way to have this successfully installed?

Thanks.

@LinusU
Copy link
Collaborator

LinusU commented Aug 5, 2015

I don't think that it's possible to come around this without source changes, although it doesn't seem to hard to fix.

This is the offending line binding.gyp L66

snprintf is used in four places:

I don't know the best way to solve this, if possible maybe it could be solved in the bindings.gyp file. Otherwise something like this in init.cc and color.cc should probably solve it.

// Compatibility with Visual Studio versions prior to 2014
#ifndef snprintf
#define snprintf _snprintf
#endif

@neojhz
Copy link
Author

neojhz commented Aug 9, 2015

great. I hope this gets fixed at the source.

@relu-xz
Copy link

relu-xz commented Aug 30, 2015

Hey guys, I've posted a solution for this.

@Zorgatone
Copy link

I have the same issue, fix this please

@LinusU
Copy link
Collaborator

LinusU commented Nov 9, 2015

Pull request very welcome, feel free to try out the solution at the bottom of my last post, and post it as a pull request.

@LinusU
Copy link
Collaborator

LinusU commented Feb 15, 2016

Fixed by #670

@LinusU LinusU closed this as completed Feb 15, 2016
eirslett added a commit to eirslett/node-imagemagick-native that referenced this issue Mar 20, 2016
This solves elad#110.

It's similar to this issue on node-canvas: Automattic/node-canvas#605

Basically, Visual Studio didn't have snprintf, so it had to be polyfilled, like it has been done here. But now, in 2015, snprintf was finally implemented, which leads to it being defined twice.
This change lets me compile the project on Windows 7 x64, with Visual Studio 2015.
eirslett added a commit to eirslett/node-imagemagick-native that referenced this issue Mar 21, 2016
This solves elad#110.

It's similar to this issue on node-canvas: Automattic/node-canvas#605

Basically, Visual Studio didn't have snprintf, so it had to be polyfilled, like it has been done here. But now, in 2015, snprintf was finally implemented, which leads to it being defined twice.
This change lets me compile the project on Windows 7 x64, with Visual Studio 2015.
horiuchi pushed a commit to horiuchi/node-imagemagick-native that referenced this issue May 19, 2016
This solves elad#110.

It's similar to this issue on node-canvas: Automattic/node-canvas#605

Basically, Visual Studio didn't have snprintf, so it had to be polyfilled, like it has been done here. But now, in 2015, snprintf was finally implemented, which leads to it being defined twice.
This change lets me compile the project on Windows 7 x64, with Visual Studio 2015.
@zbjornson zbjornson added the Bug label Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants