我想在我的 C++ 框架中使用一些 Python 代码来绘制一些统计数据。我已经找到了以下帖子(关于如何在 c++ 中嵌入 python),但是按照说明并没有成功:Embed python code in C++ (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;
}
很抱歉,但我在制作文件或附加静态或动态库方面没有太多经验......
我必须遵循系统:Windows 7 + 64 Bit + Eclipse IDE for C/C++ Developers,版本:Juno Service Release 1 + mingw + python32
在路径和符号下:+添加python32的包含目录+添加库“python32”应该对应于libpython32.a+添加库路径
编译和链接似乎可以工作,但是当我尝试启动 exe 时,我收到以下消息:
“程序无法启动,因为您的计算机中缺少 python32.dll。请尝试重新安装程序以解决此问题。”
我无法理解此消息,因为我尝试将静态库 (libpython32.a) 添加到源中。你能在正确的方向轻轻推动我吗?
非常感谢您的帮助!
编辑:添加了 makefile 和 objects.mk
制作文件################################################ ############################### 自动生成的文件。不要编辑!################################################# ##############################
-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
对象.MK
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS := -lgdi32 -ljpeg-8 -ltiff-5 -lpython32