How to compile c code with python API integration on Mac M1?

Viewed 148

I've been trying to learn how to use a python integration in C. But I've been stuck on compiling my C file with gcc. I work on an M1 Pro MacBook.

Here's my code :

#include <stdio.h>
#include <Python/Python.h>
    
int main()
{
    PyObject* pInt;
    
    Py_Initialize();
    
    PyRun_SimpleString("print('Hello World from Embedded Python!!!')");
        
    Py_Finalize();
    
    printf("\nPress any key to exit...\n");
    getchar();
    return 0;
}

At the beginning I was using :

#include <Python.h>

But I found that in Mac OS you're suppose to use the frameworks and them run you gcc commande like so :

āžœ  CxPy_integration gcc CodeSource.c -o prog.out -framework Python 

But doing like this I receive an error like that :

ld: cannot link directly with dylib/framework, your binary is not an allowed client of /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks//Python.framework/Python.tbd for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

And I don't understand how to get my code working.

0 Answers
Related