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

2

21

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 architecture 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?

Exanthema answered 27/8, 2011 at 18:43 Comment(0)
S
0

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.

Selfsustaining answered 28/9, 2011 at 5:48 Comment(3)
-m32 does not work. It still adds the 64 bit flag in there. I had to write a sed command to change the 64 bit flags to 32 bit flags in config and I get a 64 bit build. Can I force it to only do 64 bit?Exanthema
I'm not sure I understand you. Setting the arch flag to x86_64 or i386 means the processor family. Setting the m64 or m32 flag means the instructions generated. The x86_64 family can handle both 64 and 32 bit instructions. You're saying you changed the 64 bit flag (which one exactly?) to 32 bit and got a 64 bit build? If you want only 64 bit, you may not use the i386 flag.Selfsustaining
The issue is that waf is adding these flags not the user - and the user only wants the -arch x86_64Shirleeshirleen
L
2

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.)

Latticework answered 16/4, 2015 at 5:40 Comment(0)
S
0

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.

Selfsustaining answered 28/9, 2011 at 5:48 Comment(3)
-m32 does not work. It still adds the 64 bit flag in there. I had to write a sed command to change the 64 bit flags to 32 bit flags in config and I get a 64 bit build. Can I force it to only do 64 bit?Exanthema
I'm not sure I understand you. Setting the arch flag to x86_64 or i386 means the processor family. Setting the m64 or m32 flag means the instructions generated. The x86_64 family can handle both 64 and 32 bit instructions. You're saying you changed the 64 bit flag (which one exactly?) to 32 bit and got a 64 bit build? If you want only 64 bit, you may not use the i386 flag.Selfsustaining
The issue is that waf is adding these flags not the user - and the user only wants the -arch x86_64Shirleeshirleen

© 2022 - 2024 — McMap. All rights reserved.