问题
I am trying to install the "opencv4nodejs" package on a MAC by running this command:
CXXFLAGS=-std=gnu++11 npm i -g opencv4nodejs
That gives me the following error:
/usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/opencv/modules/highgui/src/window_cocoa.mm:269:25: error: non-constant-expression cannot be narrowed from type 'int' to 'CGFloat' (aka 'double') in initializer list [-Wc++11-narrowing]
NSSize size = { width, height };
^~~~~
/usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/opencv/modules/highgui/src/window_cocoa.mm:269:25: note: insert an explicit cast to silence this issue
NSSize size = { width, height };
^~~~~
static_cast<CGFloat>( )
/usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/opencv/modules/highgui/src/window_cocoa.mm:269:32: error: non-constant-expression cannot be narrowed from type 'int' to 'CGFloat' (aka 'double') in initializer list [-Wc++11-narrowing]
NSSize size = { width, height };
^~~~~~
/usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/opencv/modules/highgui/src/window_cocoa.mm:269:32: note: insert an explicit cast to silence this issue
NSSize size = { width, height };
^~~~~~
static_cast<CGFloat>( )
I found this answer that talks about the -Wno-c++11-narrowing
flag to ignore that error.
The problem is that I can't figure out how to pass that flag to the npm
command.
I've tried: CXXFLAGS=-std=c++11=-Wno-c++11-narrowing npm i -g opencv4nodejs
without success.
How can I pass that C++ flag down to the npm
command?
回答1:
The command CXXFLAGS=-std=c++11=-Wno-c++11-narrowing npm i -g opencv4nodejs
sets the CXXFLAGS variable to "-std=c++11=-Wno-c++11-narrowing" and runs the npm command.
But you don't really want the -std compiler option set to "c++11=-Wno-c++11-narrowing" - what you really want is two parameters separated by a space.
The problem is that you can't just stick in a space because CXXFLAGS=-std=c++11 -Wno-c++11-narrowing ...
tries to run a command called "-Wno-c++11-narrowing".
The solution is to escape the space with a backslash so that the shell doesn't interpret it as the delimiter between the variable and the command.
What you really want is:
CXXFLAGS=-std=c++11\ -Wno-c++11-narrowing npm i -g opencv4nodejs
来源:https://stackoverflow.com/questions/60107083/how-to-pass-c11-flag-down-to-npm-install