MacOS 和 Apple M1 芯片上的 CPython 问题

发布于 2025-01-09 03:15:46 字数 1416 浏览 1 评论 0原文

我最近将内容转移到一台运行 macOS Monterey 的新 Apple M1 笔记本电脑上,并且在尝试从 C++ 调用 Python 函数的一段非常简单的代码方面遇到了一些问题。 此处提供了具体示例。

我通过 Homebrew 安装了新版本的 Python 3.9.10,但我的编译器似乎没有检测到,因为我得到了以下信息错误:

surrutiaquir$ g++ -o main_ctp_fN_grid ctp_fN_grid.cpp -lgsl -lm -lgslcblas -std=c++11
Undefined symbols for architecture arm64:
  "_PyDict_GetItemString", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyImport_Import", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyImport_ImportModule", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyList_Append", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyModule_GetDict", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyObject_CallObject", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyObject_GetAttrString", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyString_FromString", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_Py_Finalize", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_Py_Initialize", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我对这个问题真的很困惑,所以任何指导将不胜感激。谢谢!

I recently moved my content to a new Apple M1 laptop running macOS Monterey and I have some problems with a very simple piece of code that tries to call a Python function from C++. A concrete example is available here.

I installed a new version of Python 3.9.10 via Homebrew, but it seems it is not being detected by my compiler since I get the following errors:

surrutiaquir$ g++ -o main_ctp_fN_grid ctp_fN_grid.cpp -lgsl -lm -lgslcblas -std=c++11
Undefined symbols for architecture arm64:
  "_PyDict_GetItemString", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyImport_Import", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyImport_ImportModule", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyList_Append", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyModule_GetDict", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyObject_CallObject", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyObject_GetAttrString", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_PyString_FromString", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_Py_Finalize", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
  "_Py_Initialize", referenced from:
      _main in ctp_fN_grid-2fc2a2.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm really confused about this issue, so any guidance would be highly appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文