【问题标题】:How can I link python embedded in a c/c++ application如何链接嵌入在 c/c++ 应用程序中的 python
【发布时间】:2013-09-30 08:44:34
【问题描述】:

我想使用嵌入在 c++ 应用程序中的 python。 这是我的代码:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_SetProgramName(argv[0]);  
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

我已包含在 c:\log\python27\include 中以获取 Python.h,还包含在 c:\log\python27\libs 中以具有安装在 c:\log\python27 中的相应 python 链接库 它正在编译但没有链接......为什么? 我总是有以下错误:

main.o:main.cpp:(.text+0x17): undefined reference to `_imp__Py_SetProgramName'
main.o:main.cpp:(.text+0x1e): undefined reference to `_imp__Py_Initialize'
main.o:main.cpp:(.text+0x34): undefined reference to `_imp__PyRun_SimpleStringFlags'
main.o:main.cpp:(.text+0x3b): undefined reference to `_imp__Py_Finalize'

【问题讨论】:

  • 您似乎没有提供 Python.h 源文件
  • 不,我有与您的命令完全相同的链接错误!难以置信,我现在真的不知道该尝试什么!!?

标签: python c linker


【解决方案1】:

如果你使用的是python3.5,你可以使用这个简单的命令

g++  test.cpp -I/usr/include/python3.5 -lpython3.5m -o call_function

取决于你的图书馆在哪里!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多