繁体   English   中英

C ++中的Python代码

[英]Python code in C++

我想在我的C ++框架中使用一些Python代码来绘制一些统计信息。 我已经找到了以下帖子(关于如何在c ++中嵌入python ),但是遵循说明并没有带来成功: 在C ++中嵌入python代码(Windows + minGW + Python 2.7.2 + Eclipse)

#include "Python.h"
int main(int f_argc, const char* f_argv [])
{
    Py_Initialize();
    const char* pythonScript = "print 'Hello, world!'\n";
    int result = PyRun_SimpleString(pythonScript);
    Py_Finalize();
    return 0;
}

对不起,我对make文件或附加静态或动态库没有多少经验....

我必须遵循以下系统:适用于C / C ++开发人员的Windows 7 + 64 Bit + Eclipse IDE,版本:Juno Service Release 1 + mingw + python32

在路径和符号下:+添加了包含python32目录+添加了库“python32”,它应该对应于libpython32.a +添加的库路径

编译和链接似乎工作,但当我尝试启动exe时,我收到以下消息:

“程序无法启动,因为您的计算机缺少python32.dll。请尝试重新安装该程序以解决此问题。”

我无法理解这条消息,因为我尝试将静态库(libpython32.a)添加到源代码中。 你能不能给我一个正确的方向?

非常感谢您的帮助!

编辑:添加了makefile和objects.mk

MAKEFILE ################################################## ################################自动生成的文件。 不要编辑! ################################################## ##############################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: Sandbox.exe

# Tool invocations
Sandbox.exe: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cross G++ Linker'
g++ -L"C:\Python32\libs" -o "Sandbox.exe" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '

# Other Targets
clean:
-$(RM)     $(C++_DEPS)$(OBJS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) Sandbox.exe
-@echo ' '

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

OBJECTS.MK

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS := -lgdi32 -ljpeg-8 -ltiff-5 -lpython32

在Windows上,程序搜索路径和共享库搜索路径由相同的环境变量PATH 要嵌入Python,您需要在PATH上放置包含python32.dll的目录,通常是c:\\python3.2

解释如何在Windows上更改PATH很容易用谷歌搜索; 例如,看看这个解释它用于运行Python的视频广播 ,或者这个解释Ruby过程的答案

在Windows上的Python FAQ中也介绍了在Windows上运行Python

您经常使用的静态库(libpython32.a)不是真正的静态库,它只包含python32.dll的定义。 所以它只是python32.dll的包装器。

你必须在Windows PATH中添加python安装文件夹,以便Windows可以自己找到dll。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM