4

I want to use some Python code in my C++ framework to plot some statistics. I have already found the following posting (about how to embedd python in c++) but following the instructions did not lead to success: 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 am sorry, but I do not have much experience with make files or attaching static or dynamic libraries....

I have to following system: Windows 7 + 64 Bit + Eclipse IDE for C/C++ Developers, Version: Juno Service Release 1 + mingw + python32

under path and symbols: + added include directory of python32 + added library "python32" which should correspond to libpython32.a + added library path

The compiling and linking seems to work, but when I try to start the exe, I get the following message:

"The program can't start because python32.dll is missing from your computer. Try reinstalling the program to fix this problem."

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

Thank you very much for your help!

EDIT: added makefile and objects.mk

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

-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
Community
  • 1
  • 1
bobby
  • 115
  • 8
  • BTW Also consider the opposite: make your C++ statistics code into a Python module. SWIG will make it easier for you. – Kos Dec 08 '12 at 20:27
  • See [Embedding Python on Windows: why does it have to be a DLL?](http://stackoverflow.com/q/3953039/222914) – Janne Karila Dec 08 '12 at 20:56

2 Answers2

3

On Windows the program search path and the shared library search path are controled by the same environment variable, PATH. To embed Python, you need to put the directory that contains python32.dll, typically c:\python3.2, on your PATH.

Explanations how to change PATH on Windows are easily googled; see for example this videocast that explains it for running Python, or this SO answer that explains the procedure for Ruby.

Running Python on Windows is also covered in the Python on Windows FAQ.

Community
  • 1
  • 1
user4815162342
  • 141,790
  • 18
  • 296
  • 355
0

The static library (libpython32.a) you throught is not a real static library, it contains only the definiation of python32.dll. so it is nothing but a wrapper to python32.dll.

you must add the python install folder in your Windows PATH, so that Windows could found the dll by itself.

ray_linn
  • 1,382
  • 10
  • 14