[英]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
您經常使用的靜態庫(libpython32.a)不是真正的靜態庫,它只包含python32.dll的定義。 所以它只是python32.dll的包裝器。
你必須在Windows PATH中添加python安裝文件夾,以便Windows可以自己找到dll。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.