我试图在wsl 2中安装memwatch,但我得到了一个编译错误:yarn add memwatch
> gyp info spawn make
> gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
> make: Entering directory '/home/jpprade/nodeproject/node_modules/memwatch/build'
> CXX(target) Release/obj.target/memwatch/src/heapdiff.o
> In file included from ../src/heapdiff.cc:5:
> ../src/heapdiff.hh:15:5: error: expected class-name before ‘{’ token
> 15 | {
全栈:
yarn add memwatch
yarn add v1.22.19
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
warning Pattern ["cors@latest"] is trying to unpack in the same destination "/home/jpprade/.cache/yarn/v6/npm-cors-2.8.5-eac11da51592dd86b9f06f6e7ac293b3df875d29-integrity/node_modules/cors" as pattern ["[email protected]","cors@~2.8.5","[email protected]","cors@~2.8.5","cors@~2.8.5"]. This could result in non-deterministic behavior, skipping.
warning Pattern ["object-assign@latest"] is trying to unpack in the same destination "/home/jpprade/.cache/yarn/v6/npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863-integrity/node_modules/object-assign" as pattern ["object-assign@^4","object-assign@^4.1.1","object-assign@^4.1.0","object-assign@^4.0.1","object-assign@^4","object-assign@^4.0.1","object-assign@^4.1.1"]. This could result in non-deterministic behavior, skipping.
warning Pattern ["send@latest"] is trying to unpack in the same destination "/home/jpprade/.cache/yarn/v6/npm-send-0.18.0-670167cc654b05f5aa4a767f9113bb371bc706be-integrity/node_modules/send" as pattern ["[email protected]","[email protected]"]. This could result in non-deterministic behavior, skipping.
[4/5] Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "tslib@^1.10.0".
warning "@nrwl/angular > [email protected]" has incorrect peer dependency "rxjs@^6.5.3".
warning "@nrwl/schematics > @nrwl/[email protected]" has incorrect peer dependency "prettier@^1.18.2".
warning "@nrwl/schematics > @nrwl/angular > @nrwl/[email protected]" has unmet peer dependency "cypress@^3.8.2".
warning "@nrwl/schematics > @nrwl/angular > @nrwl/cypress > @cypress/[email protected]" has incorrect peer dependency "webpack@^4.18.1".
warning " > [email protected]" has unmet peer dependency "postcss@^8.4.29".
warning " > [email protected]" has unmet peer dependency "postcss@^8.3.3".
[5/5] Building fresh packages...
[1/23] ⠐ electron
[-/23] ⠐ waiting...
[17/23] ⠐ canvas
[-/23] ⠐ waiting...
error /home/jpprade/nodeproject/node_modules/memwatch: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /home/jpprade/nodeproject/node_modules/memwatch
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 3.10.4 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/home/jpprade/.config/yarn/global/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/jpprade/nodeproject/node_modules/memwatch/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/jpprade/.config/yarn/global/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/jpprade/.cache/node-gyp/18.18.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/jpprade/.cache/node-gyp/18.18.0',
gyp info spawn args '-Dnode_gyp_dir=/home/jpprade/.config/yarn/global/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/home/jpprade/.cache/node-gyp/18.18.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/jpprade/nodeproject/node_modules/memwatch',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/jpprade/nodeproject/node_modules/memwatch/build'
CXX(target) Release/obj.target/memwatch/src/heapdiff.o
In file included from ../src/heapdiff.cc:5:
../src/heapdiff.hh:15:5: error: expected class-name before ‘{’ token
15 | {
| ^
../src/heapdiff.hh:17:34: error: ‘v8::Handle’ has not been declared
17 | static void Initialize ( v8::Handle<v8::Object> target );
| ^~
../src/heapdiff.hh:17:44: error: expected ‘,’ or ‘...’ before ‘<’ token
17 | static void Initialize ( v8::Handle<v8::Object> target );
| ^
../src/heapdiff.hh:19:20: error: ‘Handle’ in namespace ‘v8’ does not name a template type; did you mean ‘JobHandle’?
19 | static v8::Handle<v8::Value> New( const v8::Arguments& args );
| ^~~~~~
| JobHandle
../src/heapdiff.hh:20:20: error: ‘Handle’ in namespace ‘v8’ does not name a template type; did you mean ‘JobHandle’?
20 | static v8::Handle<v8::Value> End( const v8::Arguments& args );
| ^~~~~~
| JobHandle
../src/heapdiff.cc: In constructor ‘heapdiff::HeapDiff::HeapDiff()’:
../src/heapdiff.cc:30:34: error: class ‘heapdiff::HeapDiff’ does not have any field named ‘ObjectWrap’
30 | heapdiff::HeapDiff::HeapDiff() : ObjectWrap(), before(NULL), after(NULL),
| ^~~~~~~~~~
../src/heapdiff.cc: At global scope:
../src/heapdiff.cc:49:1: error: variable or field ‘Initialize’ declared void
49 | heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
| ^~~~~~~~
../src/heapdiff.cc:49:38: error: ‘Handle’ is not a member of ‘v8’; did you mean ‘JobHandle’?
49 | heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
| ^~~~~~
| JobHandle
../src/heapdiff.cc:49:55: error: expected primary-expression before ‘>’ token
49 | heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
| ^
../src/heapdiff.cc:49:57: error: ‘target’ was not declared in this scope
49 | heapdiff::HeapDiff::Initialize ( v8::Handle<v8::Object> target )
| ^~~~~~
../src/heapdiff.cc:61:5: error: ‘Handle’ in namespace ‘v8’ does not name a template type; did you mean ‘JobHandle’?
61 | v8::Handle<v8::Value>
| ^~~~~~
| JobHandle
../src/heapdiff.cc:88:33: error: ‘Handle’ does not name a type
88 | static string handleToStr(const Handle<Value> & str)
| ^~~~~~
../src/heapdiff.cc:88:39: error: expected ‘,’ or ‘...’ before ‘<’ token
88 | static string handleToStr(const Handle<Value> & str)
| ^
../src/heapdiff.cc: In function ‘std::string handleToStr(int)’:
../src/heapdiff.cc:90:37: error: ‘str’ was not declared in this scope; did you mean ‘std’?
90 | String::Utf8Value utfString(str->ToString());
| ^~~
| std
../src/heapdiff.cc: In function ‘void buildIDSet(std::set<long unsigned int>*, const v8::HeapGraphNode*, int&)’:
../src/heapdiff.cc:97:21: error: ‘v8::HandleScope::HandleScope()’ is protected within this context
97 | v8::HandleScope scope;
| ^~~~~
In file included from /home/jpprade/.cache/node-gyp/18.18.0/include/node/v8-array-buffer.h:12,
from /home/jpprade/.cache/node-gyp/18.18.0/include/node/v8.h:24,
from ../src/heapdiff.hh:8,
from ../src/heapdiff.cc:5:
/home/jpprade/.cache/node-gyp/18.18.0/include/node/v8-local-handle.h:96:13: note: declared protected here
96 | V8_INLINE HandleScope() = default;
| ^~~~~~~~~~~
../src/heapdiff.cc:105:33: error: cannot convert ‘v8::Local<v8::String>’ to ‘int’
105 | handleToStr(cur->GetName()).compare("HeapDiff") == 0)
| ~~~~~~~~~~~~^~
| |
| v8::Local<v8::String>
../src/heapdiff.cc:88:27: note: initializing argument 1 of ‘std::string handleToStr(int)’
88 | static string handleToStr(const Handle<Value> & str)
| ^~~~~~~~~~~~
../src/heapdiff.cc:111:15: error: ‘const class v8::HeapGraphNode’ has no member named ‘GetSelfSize’; did you mean ‘GetShallowSize’?
111 | s += cur->GetSelfSize();
| ^~~~~~~~~~~
| GetShallowSize
../src/heapdiff.cc: In function ‘void manageChange(changeset&, const v8::HeapGraphNode*, bool)’:
../src/heapdiff.cc:174:50: error: cannot convert ‘v8::Local<v8::String>’ to ‘int’
174 | type.append(handleToStr(node->GetName()));
| ~~~~~~~~~~~~~^~
| |
| v8::Local<v8::String>
../src/heapdiff.cc:88:27: note: initializing argument 1 of ‘std::string handleToStr(int)’
88 | static string handleToStr(const Handle<Value> & str)
| ^~~~~~~~~~~~
../src/heapdiff.cc:202:29: error: ‘const class v8::HeapGraphNode’ has no member named ‘GetSelfSize’; did you mean ‘GetShallowSize’?
202 | i->second.size += node->GetSelfSize() * (added ? 1 : -1);
| ^~~~~~~~~~~
| GetShallowSize
../src/heapdiff.cc: At global scope:
../src/heapdiff.cc:211:8: error: ‘Handle’ does not name a type
211 | static Handle<Value> changesetToObject(changeset & changes)
| ^~~~~~
../src/heapdiff.cc:230:12: error: ‘Handle’ in namespace ‘v8’ does not name a template type; did you mean ‘JobHandle’?
230 | static v8::Handle<Value>
| ^~~~~~
| JobHandle
../src/heapdiff.cc:300:5: error: ‘Handle’ in namespace ‘v8’ does not name a template type; did you mean ‘JobHandle’?
300 | v8::Handle<Value>
| ^~~~~~
| JobHandle
../src/heapdiff.cc:162:13: warning: ‘void manageChange(changeset&, const v8::HeapGraphNode*, bool)’ defined but not used [-Wunused-function]
162 | static void manageChange(changeset & changes, const HeapGraphNode * node, bool added)
| ^~~~~~~~~~~~
../src/heapdiff.cc:23:15: warning: ‘s_startTime’ defined but not used [-Wunused-variable]
23 | static time_t s_startTime;
| ^~~~~~~~~~~
make: *** [memwatch.target.mk:114: Release/obj.target/memwatch/src/heapdiff.o] Error 1
make: Leaving directory '/home/jpprade/nodeproject/node_modules/memwatch/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/jpprade/.config/yarn/global/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack at ChildProcess.emit (node:events:517:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:292:12)
gyp ERR! System Linux 5.10.102.1-microsoft-standard-WSL2
gyp ERR! command "/home/jpprade/.nvm/versions/node/v18.18.0/bin/node" "/home/jpprade/.yarn/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/jpprade/nodeproject/node_modules/memwatch
我该怎么解决这个问题?
谢谢你,谢谢
编辑:这是运行编译的命令:
g++ -o Release/obj.target/memwatch/src/heapdiff.o ../src/heapdiff.cc '-DNODE_GYP_MODULE_NAME=memwatch' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DBUILDING_NODE_EXTENSION' -I/home/jpprade/.cache/node-gyp/18.18.0/include/node -I/home/jpprade/.cache/node-gyp/18.18.0/src -I/home/jpprade/.cache/node-gyp/18.18.0/deps/openssl/config -I/home/jpprade/.cache/node-gyp/18.18.0/deps/openssl/openssl/include -I/home/jpprade/.cache/node-gyp/18.18.0/deps/uv/include -I/home/jpprade/.cache/node-gyp/18.18.0/deps/zlib -I/home/jpprade/.cache/node-gyp/18.18.0/deps/v8/include -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++17 -MMD -MF ./Release/.deps/Release/obj.target/memwatch/src/heapdiff.o.d.raw -c
编辑2:我添加了#include<node_object_wrap.h>,因为此文件存在于节点源中,但从未包括在内,这解决了错误,但给予新的。
In file included from ../src/heapdiff.cc:5:
../src/heapdiff.hh:18:34: error: ‘v8::Handle’ has not been declared
18 | static void Initialize ( v8::Handle<v8::Object> target );
编辑3:只是这个版本没有更新节点源代码,我切换到node-memwatch-new,它工作了。
1条答案
按热度按时间iqxoj9l91#
node-memwatch与最新节点不兼容。它编译时包含node.h,该node.h已随时间更改,从而导致编译错误。
使用node-memwatch-new