补充
This commit is contained in:
32
CPython/1.c
Normal file
32
CPython/1.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <Python.h>
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
// gcc 1.c -ID:\Python312\include -LD:\Python312\libs -lpython312 -static-libgcc -o 1
|
||||
int main() {
|
||||
SetDllDirectoryW(L"D:\\Python312");
|
||||
|
||||
PyConfig config;
|
||||
PyConfig_InitPythonConfig(&config);
|
||||
config.home = Py_DecodeLocale("D:\\Python312", NULL);
|
||||
|
||||
PyStatus status = Py_InitializeFromConfig(&config);
|
||||
PyConfig_Clear(&config);
|
||||
|
||||
if (PyStatus_Exception(status)) {
|
||||
fprintf(stderr, "Failed to initialize Python: %s\n", status.err_msg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject* py_num = PyLong_FromLong(12345);
|
||||
|
||||
PyObject* py_str = PyObject_Str(py_num);
|
||||
const char* c_str = PyUnicode_AsUTF8(py_str);
|
||||
printf("%s\n", c_str);
|
||||
|
||||
Py_DECREF(py_str);
|
||||
Py_DECREF(py_num);
|
||||
|
||||
Py_Finalize();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user