Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Interfacing C++ and Python (Part 1 & 2 Sample source code)

Interfacing C++ and Python (Part 1 & 2 Sample source code)

Nit
Abwood's Coding Notes · · 1 min read
2,659 0
By request, I'm attaching some sample source code that demonstrates the topics covered in my last two postings. This is a basic solution for calling into Python from C++.

I've also included in the attached zipfile, notes on how to configure a Visual Studio 2008 solution to use Python26. I expect it is straightforward to translate these steps to work with a different compiler, or another version of Python. For completeness, these notes are included here:

Notes for creating the Project in Visual Studio 2008
Assumes Python26 is installed at C:\Python26, so be sure to update the paths listed below if you are using a different version of python.
  • Create a New Project --> Win32 Console Application, No precompiled Headers, Empty Project
  • Add main.cpp, pythonCallbacks.h, pythonCallbacks.cpp files to solution
  • Right click on PythonCppExample --> Properties
    • C/C++ --> General --> Additional Include Directories = C:\Python26\include
    • Linker --> General --> Additional Library Directories = C:\Python26\libs
    • (NOTE: Notice it is the libs directory, not the Lib directory)
    • Linker --> Input --> Additional Dependencies = python26.lib

Discussion

Loading comments...