如何将C ++ 11标志传递给"npm install"? [英] How to pass C++11 flag down to "npm install"?

查看:78
本文介绍了如何将C ++ 11标志传递给"npm install"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过运行以下命令在MAC上安装"opencv4nodejs"软件包:

I am trying to install the "opencv4nodejs" package on a MAC by running this command:

CXXFLAGS=-std=gnu++11 npm i -g opencv4nodejs

这给了我以下错误:

/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>( )

我找到了答案,该答案涉及到 -Wno-c ++ 11-缩小>标志以忽略该错误.

I found this answer that talks about the -Wno-c++11-narrowing flag to ignore that error.

问题是我不知道如何将该标志传递给 npm 命令.

The problem is that I can't figure out how to pass that flag to the npm command.

我尝试过: CXXFLAGS = -std = c ++ 11 = -Wno-c ++ 11-缩小npm i -g opencv4nodejs没有成功.

如何将C ++标志传递给 npm 命令?

How can I pass that C++ flag down to the npm command?

推荐答案

命令 CXXFLAGS = -std = c ++ 11 = -Wno-c ++ 11-缩小npm i -g opencv4nodejs 将CXXFLAGS变量设置为"-std = c ++ 11 = -Wno-c ++ 11-narrowing"并运行npm命令.

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.

但是您真的不希望将-std编译器选项设置为"c ++ 11 = -Wno-c ++ 11-narrowing"-您真正想要的是两个参数,两个参数之间用空格隔开.

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.

问题是您不能只停留在空格中,因为 CXXFLAGS = -std = c ++ 11 -Wno-c ++ 11-narrowing ... 试图运行命令称为"-Wno-c ++ 11-缩小".

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.

您真正想要的是:

CXXFLAGS=-std=c++11\ -Wno-c++11-narrowing npm i -g opencv4nodejs

这篇关于如何将C ++ 11标志传递给"npm install"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆