2

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?

  • 2
    Putting an equals sign just makes the -std setting equal to "c++11=-W..." I think you want `CXXFLAGS=-std=c++11\ -Wno-c++11-narrowing npm i -g opencv4nodejs` so that the space is escaped with a backslash so that the shell knows the -W... should be part of the CXXFLAGS and not the name of the executable. – Jerry Jeremiah Feb 07 '20 at 04:32
  • That worked @JerryJeremiah! Thank you :) If you answer the question I will accept it. – Bitcoin Cash - ADA enthusiast Feb 07 '20 at 06:01

1 Answers1

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
Jerry Jeremiah
  • 9,045
  • 2
  • 23
  • 32