How to pass C++11 flag down to “npm install”?

女生的网名这么多〃 提交于 2021-02-11 13:32:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!