Compiling and linking C extension for Python in Xcode for Mac

后端 未结 2 750
悲哀的现实
悲哀的现实 2021-01-13 12:57

I am trying to compile a simple C extension in Mac to use with Python, and all works well in the command line. Code and gcc command that works are presented below. Now

相关标签:
2条回答
  • 2021-01-13 13:41

    I've had success debugging unit-tested C extensions in XCode 4.6 using setuptools, virtualenv, unittest and GDB as the debugger.

    I use virtualenvwrapper to create a virtualenv for the project and then set ~/.virtualenvs/module_name/bin/python as the executable to debug.

    The single argument to pass to the virtualenv python interpreter in the Run configuration is the path to your test.py.

    I then set GDB rather than None as the debugger launching it automatically.

    The last step is to pass "setup.py install" as the arguments to your build tool (~/.virtualenvs/module_name/bin/python) on your test target's External Build Tool Configuration pane. The virtualenv provides a fairly simple way for you to install the shared object for your C extension into the test script python interpreter's library path without actually installing it into the global site-packages for your host.

    With this setup I can call the extension code from a python script (the ultimate aim) and still debug the C code using XCode's GUI debug support.

    If I haven't described this clearly please let me know and I'll share an example project.

    0 讨论(0)
  • 2021-01-13 13:48

    This guy seems to be having the same problem.

    I've figured out the problem. Even though I changed the setting in xcode to specify output type "dynamic library" or "bundle", xcode was ignoring the setting. Starting a new BSD dynamic library project solved the issues I was seeing. Thanks for the help!

    0 讨论(0)
提交回复
热议问题