[英]Linking Python into my C++ code on windows - linker error
I have an error trying to link python into my C++ code. 尝试将python链接到我的C ++代码时出现错误。
This is the error line I am getting: 这是我得到的错误行:
C:\Python27\libs/libpython27.a(dmmes00855.o):(.idata$7+0x0): undefined reference to `_head_C__build27_cpython_PCBuild_libpython27_a'
collect2.exe: error: ld returned 1 exit status
For background, here is minimal case: 对于背景,这是最小的情况:
#include <Python.h>
int main()
{
Py_Initialize();
}
I am using scons to build: 我正在使用scons构建:
import os
env = Environment(ENV = os.environ)
env.Append(CPPPATH = "C:/Python27/include/")
env.Append(LIBPATH = "C:/Python27/libs/")
env.Append(LIBS = "python27")
env.Program("test", "test.cpp")
It generates the following commands: 它生成以下命令:
g++ -o test.o -c -IC:\Python27\include test.cpp
g++ -o test.exe test.o -LC:\Python27\libs -lpython27
Compiler is the mingw that I have as part of my Qt download. Qt下载中包含编译器。
No problems with g++
commands. g++
命令没有问题。 Apparently, this is a bug . 显然,这是一个错误 。
A bugfix release 2.7.10
is currently available. 一个错误修复版本2.7.10
当前可用。 First of all Upgrade to 2.7.10
首先升级到2.7.10
Then you need to create libpython27.a
with 然后您需要使用以下命令创建libpython27.a
gendef.exe python27.dll
and 和
dlltool.exe --dllname python27.dll --def python27.def --output-lib libpython27.a
and place it in C:\\Python27\\libs
并将其放在C:\\Python27\\libs
Now compiling with MinGW will work fine. 现在,使用MinGW编译可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.