Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'cflags' parameter is broken in gyp on OS X?

This is a barebones GYP file to compile 1 C source file. We are demonstrating that the cflags parameter in gyp files gets completely ignored :(

$ ../gyp/gyp -f make --depth=. hello.gyp
$ V=1 make
  cc   -fasm-blocks -mpascal-strings -Os -gdwarf-2  -MMD -MF out/Default/.deps/out/Default/obj.target/hello/hello.o.d.raw  -c -o out/Default/obj.target/hello/hello.o hello.c
  ./gyp-mac-tool flock out/Default/linker.lock g++ -Lout/Default   -o "out/Default/hello" out/Default/obj.target/hello/hello.o 
  LINK(target) out/Default/hello: Finished

We would expect a -ObjC flag to be present somewhere in the cc command, but it's not...

#include <stdio.h>
int main () {
printf("Hello\n");
return 0;
}
{
'targets': [
{
'target_name': 'hello',
'type': 'executable',
'cflags': [
'-ObjC'
],
'sources': [
'hello.c'
]
}
]
}
@springmeyer

This comment has been minimized.

Copy link

commented Jan 10, 2012

I think it's that gyp better at building xcode/visual studio projects and perhaps not well tested with the make generator. I think this should work for you if you are on osx:

Index: pylib/gyp/generator/make.py
===================================================================
--- pylib/gyp/generator/make.py (revision 1137)
+++ pylib/gyp/generator/make.py (working copy)
@@ -1152,15 +1152,15 @@
           quoter=EscapeCppDefine)

       if self.flavor == 'mac':
-        cflags = self.xcode_settings.GetCflags(configname)
-        cflags_c = self.xcode_settings.GetCflagsC(configname)
-        cflags_cc = self.xcode_settings.GetCflagsCC(configname)
+        #cflags = self.xcode_settings.GetCflags(configname)
+        #cflags_c = self.xcode_settings.GetCflagsC(configname)
+        #cflags_cc = self.xcode_settings.GetCflagsCC(configname)
         cflags_objc = self.xcode_settings.GetCflagsObjC(configname)
         cflags_objcc = self.xcode_settings.GetCflagsObjCC(configname)
-      else:
-        cflags = config.get('cflags')
-        cflags_c = config.get('cflags_c')
-        cflags_cc = config.get('cflags_cc')
+      #else:
+      cflags = config.get('cflags')
+      cflags_c = config.get('cflags_c')
+      cflags_cc = config.get('cflags_cc')

       self.WriteLn("# Flags passed to all source files.");
       self.WriteList(cflags, 'CFLAGS_%s' % configname)
@paddybyers

This comment has been minimized.

Copy link

commented Jan 10, 2012

cflags only seems to be supported for Scons.

This works both with make and xcode generators on Mac:

{
  'targets': [
    {
      'target_name': 'hello',
      'type': 'executable',
      'xcode_settings': {
        'OTHER_CFLAGS': [
          '-ObjC'
        ],
      },
      'sources': [
          'hello.c'
      ]
    }
  ]
}
@TooTallNate

This comment has been minimized.

Copy link
Owner Author

commented Jan 10, 2012

Thanks @paddybyers. Indeed it seems that adding an xcode_settings block is the preferred way of doing this.

@indutny

This comment has been minimized.

Copy link

commented Mar 28, 2012

Thanks, @google. I found this gist and fixed my problem: indutny/candor@40a27c8#diff-0

@zdne

This comment has been minimized.

Copy link

commented Apr 4, 2013

This issues is still present. @paddybyers approach still works.

@karimcitoh

This comment has been minimized.

Copy link

commented Nov 20, 2015

Any solution of how to make cflags work on Windows?

@nitriques

This comment has been minimized.

Copy link

commented Jul 13, 2017

Still no solution to make it work on Windows ?

@mhirsch

This comment has been minimized.

Copy link

commented Aug 30, 2017

This seems to work in linux now with node-gyp v3.6.2 (e.g. gyp pays attention to the cflags field)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.