Python code in C ++

I want to use some Python code in my C ++ platform to build some statistics. I already found the following publication (on how to embed python in C ++), but following the instructions did not succeed: 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; } 

I'm sorry, but I do not have much experience with make files or adding static or dynamic libraries ....

I have to follow the following system: Windows 7 + 64 bit + Eclipse IDE for C / C ++ developers, version: Juno Service Release 1 + mingw + python32

by path and symbols: + python32 directory is added + python32 library is added, which should correspond to libpython32.a + library path is added

Compiling and binding seem to work, but when I try to run exe, I get the following message:

"The program cannot start because the python32.dll file is missing on your computer. Try reinstalling the program to fix this problem."

I cannot understand this message because I am trying to add a static library to the source (libpython32.a). Could you give me a soft push in the right direction?

Many thanks for your help!

EDIT: added makefile and objects.mk

MAKEFILE ##################################################### # ################################ # Automatically generated files. Do not change! ####################################################### #################################

 -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 
+4
source share
2 answers

On Windows, the program search path and the shared library search path are controlled by the same PATH environment variable. To implement Python, you need to put the directory containing python32.dll , usually c:\python3.2 , on your PATH .

Explanations on how to change PATH on Windows are easily processed by Google; see, for example, this video that explains this for running Python or this SO answer which explains the procedure for Ruby.

Running Python on Windows is also covered in Python on Windows FAQs.

+3
source

The static library (libpython32.a) you throught is not a real static library, it contains only the python32.dll definition. therefore, it is nothing but a shell for python32.dll.

you must add the python installation folder to your Windows PATH so that Windows can find the DLL itself.

0
source

All Articles