如何抑制“-arch”、“x86_64”在 OSX 上使用 Waf 编译 OpenGL/SDL 应用程序时的标志?

发布于 2024-12-01 11:59:39 字数 507 浏览 3 评论 0原文

我需要抑制 Waf 传递给 GCC 的“-arch x86_64 -arch i386”标志。

我正在构建一个 SDL/Opengl 应用程序。如果我链接到 32 位 SDL 运行时,我会收到错误

    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

如果我链接到 64 位 SDL 运行时,我会收到错误“未定义架构 x86_64 的符号”

编译器显然正在使用标志

-arch x86_64 -arch i386

我知道这会导致 OSX 上的 GCC 尝试编译两者架构。我想编译 64 位,或编译 32 位。如何抑制一种架构的标志?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赏烟花じ飞满天 2024-12-08 11:59:39

我发现在我的情况下,双拱标志源自 此处,具体来自 distutils.sysconfig.get_config_var('LDFLAGS')。这将返回 Python 认为您应该链接 Python 模块的 LDFLAGS。就我而言,file $(which python) 是一个“具有 2 种架构的 Mach-O 通用二进制文件”,因此 Python 认为您应该与 -arch x86_64 -arch i386 -Wl,F 链接.

我的问题是,我正在构建一个 Python 本机模块,该模块需要链接到 Python 和另一个不是用两个架构构建的库。当使用两个拱门构建我的模块时,链接失败并显示“未找到符号”,因为这两个拱门在第三方库中不可用。

由于 waf 不幸的是不允许您使用自己的标志覆盖其计算标志,正如 Automake 所做的,我只能通过直接弄乱我的 wscript 中的 ctx() 对象来解决这个问题:(

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

这会删除所有 -arch由于我还在 CFLAGS 中传递了自己的 -arch 标志,因此它现在不会被覆盖。)

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

滿滿的愛 2024-12-08 11:59:39

我不知道如何发出命令/标志来抑制其他标志。但是,要仅编译 64 位或 32 位,可以分别使用 -m64 或 -m32。由于您要针对两种体系结构进行编译,因此 -m32 可能是您唯一的选择,因为 -m64 不适用于 i386。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文