Automattic/node-canvas

'toupper': is not a member of 'std'

wxfred opened this issue · 8 comments

Issue

Win10 electron project
After installing all dependencies, rebuild canvas

..\node_modules\canvas\src\util.h(32): error C2039: 'toupper': is not a member of 'std'
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\map(20): note: see declaration of 'std'

then, I changed the source code from

inline bool streq_casein(std::string& str1, std::string& str2) {
  return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), [](char& c1, char& c2) {
    return c1 == c2 || std::toupper(c1) == std::toupper(c2);
  });
}

to

inline bool streq_casein(std::string& str1, std::string& str2) {
  return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), [](char& c1, char& c2) {
    return c1 == c2 || toupper(c1) == toupper(c2);
  });
}

Another error came out

Canvas.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)" (__imp_?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_p
tr@VBackingStore@v8@@@std@@XZ)

I have no idea about that.

Your Environment

win10
canvas 2.8.0
node v12.19.0
node-gyp v5.1.0
GTK 2
libjpeg-turbo-2.0.6-vc64.exe

same quesion in my environment:

npm ERR! e:\git_new\sprite-v3\node_modules\canvas\src\util.h(31): error C2039: "toupper": is not a member of "std" [E:\git_new\sprite-v3\node_modules\canvas\build\canvas.vcxproj]
npm ERR!   c:\program files (x86)\microsoft visual studio\2017\buildtools\vc\tools\msvc\14.16.27023\include\map(20): note: 参见“std”的声明
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@14.17.3 | win32 | x64
npm ERR! gyp info find Python using Python version 2.7.18 found at "C:\Python27\python.exe"
npm ERR! gyp info find VS using VS2017 (15.9.28307.1525) found at:
npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Python27\python.exe

@919485590 Unfortunately, there is no simple solution recently. I'll try to build my exe with my mac or a linux.
nodejs/nan#892 (comment)

wasted my time and was disappointed by windows

solved by mapbox/node-pre-gyp#526 (comment)
npm 7.22.0
node 14.17.5

这个报错是nan编译时抛出来的,我测试通过的解决方案:

  1. 手动安装nan@2.14.0
  2. 删除/node_modules/canvas/node_modules/nan/文件夹
  3. 执行electron-rebuild
  4. 抛出toupper异常再根据你的方法修改
  5. 执行electron-rebuild

The second error (unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)...) is addressed in v2.9.0 (#1944, affects Node.js v14+). You can also reinstall from scratch (delete node_modules) so that a newer version of Nan gets installed.

The first issue should be fixed by #1960.