我想在我的C++框架中使用一些Python代碼來繪製一些統計信息。我已經發現了以下發布(關於如何使嵌入在C++中的Python),但下面的說明並沒有導致成功:Embed python code in C++ (Windows + minGW + Python 2.7.2 + Eclipse)C++中的Python代碼
#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文件或附加太多的經驗靜態或動態庫....
我不得不以下系統: 視窗7 + 64 +位的Eclipse IDE爲C/C++開發人員,版本:朱諾服務版本1 + mingw的+ python32
下路徑和符號: +增加了包含python32 01的目錄添加庫「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: [email protected]'
@echo 'Invoking: Cross G++ Linker'
g++ -L"C:\Python32\libs" -o "Sandbox.exe" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: [email protected]'
@echo ' '
# Other Targets
clean:
-$(RM) $(C++_DEPS)$(OBJS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) Sandbox.exe
[email protected] ' '
.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
把這裏放在你的makefile文件 – 0x90
順便說一句:也可以考慮相反的做法:讓你的C++統計代碼進入Python模塊。 SWIG會讓你更容易。 – Kos
請參閱[在Windows上嵌入Python:爲什麼它必須是DLL?](http://stackoverflow.com/q/3953039/222914) –