开发者

How do I suppress '-arch', 'x86_64' flags when compiling an OpenGL/SDL application with Waf on OSX?

I need to suppress "-arch x86_64 -arch i386" flags Waf is passing to GCC.

I am building an SDL/Opengl application. If I link against 32 bit SDL runtime I get error

    Undefined symbols for architecture i386:
  "_SDL_Quit", referenced from:
      __del_video in SDL_functions.c.2.o
      __init_video in SDL_functions.c.2.o

If I link against 64 bit SDL runtime, I get error "Undefined symbols for archi开发者_运维知识库tecture x86_64"

The compiler is apparently using flags

-arch x86_64 -arch i386

I understand that this causes GCC on OSX to try to compile for both architectures. I want to either compile for 64 bit, or compile for 32 bit. How do I suppress the flags for one architecture?


I found out in my case that the double arch flags were originating here, specifically from distutils.sysconfig.get_config_var('LDFLAGS'). This returns the LDFLAGS that Python thinks you should link Python modules with. In my case, file $(which python) is a "Mach-O universal binary with 2 architectures", so Python thinks you should link with -arch x86_64 -arch i386 -Wl,F.

My problem was that I was building a Python native module that needed to link against Python and another library which was not built with both arches. When building my module with both arches, linking failed with "symbols not found", because both arches were not available in the third-party library.

Since waf unfortunately doesn't allow you to override its computed flags with your own flags, as Automake does, I could only fix this by messing directly with my ctx() object in my wscript:

for var in ['CFLAGS_PYEMBED', 'CFLAGS_PYEXT', 'CXXFLAGS_PYEMBED',
    'CXXFLAGS_PYEXT', 'LINKFLAGS_PYEMBED', 'LINKFLAGS_PYEXT']:
    newvar = []
    for ix, arg in enumerate(ctx.env[var]):
        if '-arch' not in (arg, ctx.env[var][ix - 1]):
            newvar.append(arg)
    ctx.env[var] = newvar

(This removes all -arch flags and their arguments from the relevant variables. Since I was also passing my own -arch flag in my CFLAGS, it now does not get overridden.)


I don't know of a way to issue a command/flag to suppress other flags. However, to compile for only 64 or 32 bits, you can use -m64 or -m32, respectively. Since you're compiling for both architectures, -m32 might be your only option because -m64 won't work for i386.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜