Mac で単純な C 拡張機能をコンパイルして Python で使用しようとしていますが、すべてコマンド ラインでうまく動作します。動作するコードと gcc コマンドを以下に示します。現在、Xcode 4.5 (Mac OS10.8) で同じ拡張機能をビルドしようとしています。dylib または静的ライブラリのターゲット設定をいくつか試しましたが、常に Python で読み込めないファイルが表示され、次のエラーが表示されます。
./myModule.so: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A
私の最終的な目標は、C/C++ 拡張機能のソース コードを使用して XCode でワークスペースを作成し、それを Xcode で呼び出す Python スクリプトを作成することです。したがって、C/C++ 拡張機能をデバッグする必要がある場合は、XCode のデバッグ機能を利用できます。XCode が Python スクリプトにデバッグしないことは承知していますが、実行することはできますか?
gcc -shared -arch i386 -arch x86_64 -L/usr/lib/python2.7 -framework python -I/usr/include/python2.7 -o myModule.so myModule.c -v
#include <Python.h>
/*
 * Function to be called from Python
 */
static PyObject* py_myFunction(PyObject* self, PyObject* args)
{
    char *s = "Hello from C!";
    return Py_BuildValue("s", s);
}   
/*
 * Another function to be called from Python
 */
static PyObject* py_myOtherFunction(PyObject* self, PyObject* args)
{
    double x, y;
    PyArg_ParseTuple(args, "dd", &x, &y);
    return Py_BuildValue("d", x*y);
}
/*
 * Bind Python function names to our C functions
 */
static PyMethodDef myModule_methods[] = {
    {"myFunction", py_myFunction, METH_VARARGS},
    {"myOtherFunction", py_myOtherFunction, METH_VARARGS},
    {NULL, NULL}
};
/*
 * Python calls this to let us initialize our module
 */
void initmyModule()
{
    (void) Py_InitModule("myModule", myModule_methods);
}