2

here is my code

#include <Python/Python.h>
using namespace std;


int main(int argc, char *argv[])
{
    Py_SetProgramName(argv[0]);
    Py_Initialize();
    PyRun_SimpleString("print 1\n");
    Py_Finalize();
    return 0;
}

But something went wrong: info

And gcc my_python.c -o my_python -I/usr/include/python2.7/ -lpython2.7 is working well.Is it possible I try to call python in xcode?

2
  • Looks like you did not tell xcode to link against the python framework for your project. Commented May 23, 2016 at 17:45
  • @BarryScott I'm new about this.Can you show links?Thanks. Commented May 24, 2016 at 1:29

1 Answer 1

1

To use python in C++ in Xcode, you need to link the python framework to your .xcodeproj file.

Select your .xcodeproj file. Go to Build Phases > Link Binary With Libraries and click the + icon.

Image1

You will be prompted to select a framework. Search for Python.framework and press Add.

Image2

Try building your project again and it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.