如何在Python setup.py脚本中将标志传递给gcc?

编程入门 行业动态 更新时间:2024-10-27 22:22:32
本文介绍了如何在Python setup.py脚本中将标志传递给gcc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用C编写一个Python扩展,它需要CoreFoundation框架(除其他外).可以使用以下命令进行编译:

I'm writing a Python extension in C that requires the CoreFoundation framework (among other things). This compiles fine with:

gcc -o foo foo.c -framework CoreFoundation -framework Python

(-framework"是Apple专用的gcc扩展,但这没关系,因为无论如何我都在使用它们的特定框架)

("-framework" is an Apple-only gcc extension, but that's okay because I'm using their specific framework anyway)

我如何告诉setup.py将此标志传递给gcc?

How do I tell setup.py to pass this flag to gcc?

我尝试了这个,但是它似乎不起作用(它可以编译,但是当我尝试运行它时会抱怨未定义的符号):

I tried this, but it doesn't seem to work (it compiles, but then complains of undefined symbols when I try to run it):

from distutils.core import setup, Extension setup(name='foo', version='1.0', author='Me', ext_modules=[Extension('foo', ['foo.c'], extra_compile_args=['-framework CoreFoundation'])])

这似乎起作用:

from distutils.core import setup, Extension setup(name='foo', version='1.0', author='Me', ext_modules=[Extension('foo', ['foo.c'], extra_link_args=['-framework', 'CoreFoundation'])])

推荐答案

也许您也需要设置extra_link_args?编译源代码时使用extra_compile_args,链接结果时使用extra_link_args.

Maybe you need to set extra_link_args, too? extra_compile_args is used when compiling the source code, extra_link_args when linking the result.

更多推荐

如何在Python setup.py脚本中将标志传递给gcc?

本文发布于:2023-06-11 15:11:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/637406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   脚本   标志   如何在   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!