Node-gyp: Compiling C++/CLI under Windows

Created on 27 Jan 2015  路  2Comments  路  Source: nodejs/node-gyp

I'm trying to compile a source file as C++/CLI, but my lack of knowledge and experience in Windows systems is preventing me from moving forward.

What compiler does node-gyp uses under Windows? It seems that I need a tool called cl to compile C++/CLI (which I can access successfully from cmd.exe), with a /clr flag.

I made sure such flag appears in my bindings.gyp Windows conditions:

      ...
      'conditions': [
        ['OS=="win32"', {
          'cflags_cc': [
            '/clr'
          ],
        }],
      ...

Is anything else needed? How can I make sure node-gyp is using cl and outputting C++/CLI code?

I tried using managed code from my C++ file, but node-gyp says:

faltal error c1190: managed targeted code requires a '/clr' option

So I assume my cflags_cc option is not being used by node-gyp.

Most helpful comment

Yup node-gyp does use msvs cl.exe but to enable /clr you need to set it as a build setting

['OS=="win"', {
            'msvs_settings': {
                'VCCLCompilerTool': {                  
                  'RuntimeLibrary':'MultiThreadedDLL'
                }
            },
            'msbuild_settings': {
              'ClCompile': {
                'CompileAsManaged':'true' # can be safe, pure
              }
            }
}]

for more configuration options you can refer this file https://github.com/TooTallNate/node-gyp/blob/master/gyp/pylib/gyp/MSVSSettings.py#L659

All 2 comments

Yup node-gyp does use msvs cl.exe but to enable /clr you need to set it as a build setting

['OS=="win"', {
            'msvs_settings': {
                'VCCLCompilerTool': {                  
                  'RuntimeLibrary':'MultiThreadedDLL'
                }
            },
            'msbuild_settings': {
              'ClCompile': {
                'CompileAsManaged':'true' # can be safe, pure
              }
            }
}]

for more configuration options you can refer this file https://github.com/TooTallNate/node-gyp/blob/master/gyp/pylib/gyp/MSVSSettings.py#L659

@deepak1556 Thanks, works as expected.

Was this page helpful?
0 / 5 - 0 ratings