Combining C++ and Python

sybren

21-12-2011 09:47:30

Hey folks,

As this is my first post here, let me introduce myself. My name is Sybren, and I'm a PhD student at Utrecht University in The Netherlands. We've used Ogre with C++ before, and now we're porting our code from regular Ogre to Python-Ogre.

We're using Python 3, and so far ogre-1.7.2-rBETA-py-3.2 works fine. However, we want to access Ogre from C++ as well. We want to do something like this:

  1. Python creates the Ogre root, scene manager, render window, the whole lot.[/*:m]
  2. Python loads our C++ code as a PYD file, say our_module.pyd[/*:m]
  3. our_module.pyd fetches the Ogre root and scene manager, and needs to do things like loading entities, accessing the bone structure of an entity, etc.[/*:m][/list:u]

    In order to properly compile and link our C++ code, we need the include and lib files used to build Python-Ogre. Are these available somewhere? Or can the person that built ogre-1.7.2-rBETA-py-3.2 zip them and put them online somewhere? I've tried building the SVN version from the Python3.x branch myself, but couldn't get it to build.

    With kind regards,
    Sybren

dermont

22-12-2011 04:10:33

The developer, Andy, is fairly busy at the moment so it may take some time for him to reply to your request. This has been asked/requested a few times so there probably should be a developers SDK.

I've only built with python3 on Linux so not sure how much I can help with your Windows build but in the meantime perhaps you can post what problems/errors you are encountering building python-ogre.

sybren

22-12-2011 07:06:58

The developer, Andy, is fairly busy at the moment

There is only one developer?

This has been asked/requested a few times so there probably should be a developers SDK.

I'm glad I'm not the only one asking for this. Any idea as to an ETA?

I've only built with python3 on Linux so not sure how much I can help with your Windows build but in the meantime perhaps you can post what problems/errors you are encountering building python-ogre.

Sure, here we go. I've created a directory C:\workspace\py-ogre-workspace to put all the files in. I've checked out the Python-3.x branch into the "python-ogre-py3" directory:

svn co https://python-ogre.svn.sourceforge.net ... ython-3.x/ python-ogre-py3

I built/installed Boost::Python, CMake, Scons, (py)gccxml and Py++ 1.0 according to their installation instructions. I updated scripts/compilesource.bat to call my Visual Studio 10 compiler (the original used VS 9). We're using Boost::Python 1.48, so I updated environment.py to use this version instead. I also updated PythonOgreConfig_nt.py to match our configuration:

PATH_Boost = 'C:/workspace/rage-py32/deps/boost_1_48_0'
PATH_LIB_Boost = os.path.join(PATH_Boost, 'bin.v2/libs/python/build/msvc-10.0/release/threading-multi')
#PATH_LIB_Boost_STATIC = os.path.join(PATH_Boost, 'bin.v2/libs/python/build/msvc-10.0/release/link-static/threading-multi')
PATH_LIB_Thread_STATIC = os.path.join(PATH_Boost, 'bin.v2/libs/thread/build/msvc-10.0/release/link-static/threading-multi')
PATH_LIB_date_time_STATIC = os.path.join(PATH_Boost, 'bin.v2/libs/date_time/build/msvc-10.0/release/link-static/threading-multi')
PATH_LIB_Boost = os.path.join(PATH_Boost, 'bin.v2/libs/python_' +PythonVersionString +'/build/msvc-10.0/release/threading-multi')
gccxml_bin = os.path.join(BASE_DIR, 'gccxml-build/bin/Debug/gccxml.exe')
pyplusplus_install_dir = os.path.join(BASE_DIR, 'py++-1.0.0')
PATH_Ogre = os.path.join(BASE_DIR, 'ogre') # I change this line twice, in both places PATH_Ogre was set to c:\development\ogre.


So now it's time to go to step 4 and run:

python python-ogre-py3/BuildModule.py -r cegui ois ogre

Which gives me:

Traceback (most recent call last):
File "python-ogre-py3/BuildModule.py", line 9, in <module>
import environment
File "C:\workspace\py-ogre-workspace\python-ogre-py3\environment.py", line 710, in <module>
class ogre(pymodule):
File "C:\workspace\py-ogre-workspace\python-ogre-py3\environment.py", line 781, in ogre
Config.PATH_INCLUDE_ogreproperty,
AttributeError: 'module' object has no attribute 'PATH_INCLUDE_ogreproperty'


So I updated environment.py and removed the Config.PATH_INCLUDE_ogreproperty line (781), as I can't find any other mention of this variable. Now I get this:

PythonOgre.BuildModule: INFO Build Command echo Use MSVC to build OIS
PythonOgre.BuildModule: INFO Build Command unzip -o C:\workspace\py-ogre-workspace\downloads\ogre-v1-7-0.zip
PythonOgre.BuildModule: WARNING Task Failed
PythonOgre.BuildModule: INFO Build Command unzip -o C:\workspace\py-ogre-workspace\downloads\OgreDependencies_VC9_Ei
hort_20080203.zip
PythonOgre.BuildModule: WARNING Task Failed
PythonOgre.BuildModule: INFO Build Command echo Please use MSVC Express Edition to build Ogre Release.


I must have done something differently this time, as when I tried it last tuesday days ago it didn't give me this message about MSVC Express. Why am I asked to use the Express edition? I've built Ogre just fine with MSVC Professional.

I've attached log.out and a zip of all the python-ogre files I modified.

sybren

22-12-2011 07:51:41

Ok, that was silly. I checked environment.py and it simply echoed the message; I had interpreted it as "we've checked your system and you need MSVC Express" rather than a simple "now go build it yourself" message. I've built OIS, but that failed because the DirectX SDK Lib directory wasn't on the lib path. After adding that, it built the IOS lib (one of the demo projects failed on "LINK : fatal error LNK1104: cannot open file 'ois.lib'", but I don't care).

To build Ogre I ran cmake-gui, and set both the source and binary location to C:/workspace/py-ogre-workspace/ogre; pressed configure; I set Boost_DIR=C:/workspace/rage-py32/deps/boost_1_48_0 (my project's Boost dir) and hit the "Generate" button.

When compiling a debug build of Ogre using VS 2010 pro I get these errors:


1>------ Build started: Project: OgreMain, Configuration: Debug Win32 ------
1>Build started 22/12/2011 08:48:45.
1>InitializeBuildStatus:
1> Touching "OgreMain.dir\Debug\OgreMain.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> All outputs are up-to-date.
1>ResourceCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Link:
1> Creating library C:/workspace/py-ogre-workspace/ogre/lib/Debug/OgreMain_d.lib and object C:/workspace/py-ogre-workspace/ogre/lib/Debug/OgreMain_d.exp
1>FreeImaged.lib(FIRational.obj) : warning LNK4049: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported
1>FreeImaged.lib(ImfTileOffsets.obj) : warning LNK4049: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported
1>FreeImaged.lib(ImfScanLineInputFile.obj) : warning LNK4049: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported
1>FreeImaged.lib(ImfStandardAttributes.obj) : warning LNK4049: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported
1>FreeImaged.lib(ImfAttribute.obj) : warning LNK4049: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported
1>FreeImaged.lib(IlmThreadPool.obj) : warning LNK4217: locally defined symbol ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) imported in function __catch$?_Buynode@?$list@PAVTask@IlmThread@@V?$allocator@PAVTask@IlmThread@@@std@@@std@@IAEPAU_Node@?$_List_nod@PAVTask@IlmThread@@V?$allocator@PAVTask@IlmThread@@@std@@@2@XZ$0
[... and a lot more of these warnings ...]

1>FreeImaged.lib(ImfAttribute.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(IlmThreadPool.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(ImfTileOffsets.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ) referenced in function __catch$?_Insert_n@?$vector@V?$vector@V?$vector@_KV?$allocator@_K@std@@@std@@V?$allocator@V?$vector@_KV?$allocator@_K@std@@@std@@@2@@std@@V?$allocator@V?$vector@V?$vector@_KV?$allocator@_K@std@@@std@@V?$allocator@V?$vector@_KV?$allocator@_K@std@@@std@@@2@@std@@@2@@std@@IAEXV?$_Vector_const_iterator@V?$vector@V?$vector@_KV?$allocator@_K@std@@@std@@V?$allocator@V?$vector@_KV?$allocator@_K@std@@@std@@@2@@std@@V?$allocator@V?$vector@V?$vector@_KV?$allocator@_K@std@@@std@@V?$allocator@V?$vector@_KV?$allocator@_K@std@@@std@@@2@@std@@@2@@2@IABV?$vector@V?$vector@_KV?$allocator@_K@std@@@std@@V?$allocator@V?$vector@_KV?$allocator@_K@std@@@std@@@2@@2@@Z$0
1>FreeImaged.lib(IPTC.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(Exif.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(ImfTiledInputFile.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(ImfScanLineInputFile.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(ImfInputFile.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(ImfRgbaFile.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
1>FreeImaged.lib(ImfHeader.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)" (__imp_??1_Container_base_secure@std@@QAE@XZ)
[... and a lot more of these errors ...]

1>C:\workspace\py-ogre-workspace\ogre\bin\Debug\OgreMain_d.dll : fatal error LNK1120: 20 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:05.64

sybren

09-01-2012 10:00:45

After recompiling depdencies for VS2010, and retrying to get the wrapper code for IOS generated using "python python-ogre-py3/BuildModule.py -g ois". It now gives me this list of errors:


12-23 09:56 PythonOgre.BuildModule DEBUG INFO Creating xml file "C:\workspace\py-ogre-workspace\python-ogre-py3\code_generators\cache\ois_1.0_cache.xml" from source file "C:\workspace\py-ogre-workspace\python-ogre-py3\code_generators\ois\python_ois.h" ...
INFO gccxml cmd: ""C:\workspace\py-ogre-workspace\gccxml-build\bin\Debug\gccxml.exe" -D"_HAS_TR1=0" -I"C:\workspace\py-ogre-workspace\python-ogre-py3" -I"C:/workspace/rage-py32/deps/boost_1_48_0" -I"C:\workspace\py-ogre-workspace\ogre\SDK\include\OIS" -D"OIS_NONCLIENT_BUILD" -D"VERSION_1.0" "C:\workspace\py-ogre-workspace\python-ogre-py3\code_generators\ois\python_ois.h" -fxml="C:\workspace\py-ogre-workspace\python-ogre-py3\code_generators\cache\ois_1.0_cache.xml""
Traceback (most recent call last):
File "generate_code.py", line 360, in <module>
generate_code()
File "generate_code.py", line 275, in generate_code
, cflags=environment.ois.cflags
File "C:\Python27\lib\site-packages\pyplusplus\module_builder\builder.py", line 92, in __init__
, indexing_suite_version)
File "C:\Python27\lib\site-packages\pyplusplus\module_builder\builder.py", line 146, in __parse_declarations
decls = reader.read_files( files, compilation_mode )
File "C:\Python27\lib\site-packages\pygccxml\parser\project_reader.py", line 225, in read_files
return self.__parse_file_by_file(files)
File "C:\Python27\lib\site-packages\pygccxml\parser\project_reader.py", line 262, in __parse_file_by_file
reader.create_xml_file( header, prj_file.cached_source_file )
File "C:\Python27\lib\site-packages\pygccxml\parser\source_reader.py", line 169, in create_xml_file
raise error
pygccxml.parser.source_reader.gccxml_runtime_error_t: Error occured while running GCC-XML: C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/type_traits: In instantiation of 'std::tr1::is_scalar<unsigned int>':
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/xutility:503: instantiated from 'std::_Ptr_cat_helper<unsigned int, unsigned int>'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/memory:611: instantiated from 'void std::_Uninitialized_fill_n(_FwdIt, _Diff, const _Tval*, _Alloc&) [with _FwdIt = unsigned int*, _Diff = unsigned int, _Tval = unsigned int, _Alloc = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:1421: instantiated from 'typename std::_Vector_val<_Ty, _Ax>::_Alty::pointer std::vector<_Ty, _Ax>::_Ufill(typename std::_Vector_val<_Ty, _Ax>::_Alty::pointer, typename std::_Vector_val<_Ty, _Ax>::_Alty::size_type, const _Ty*) [with _Ty = unsigned int, _Ax = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:585: instantiated from 'void std::vector<_Ty, _Ax>::_Construct_n(typename std::_Vector_val<_Ty, _Ax>::_Alty::size_type, const _Ty*) [with _Ty = unsigned int, _Ax = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:530: instantiated from 'std::vector<_Ty, _Ax>::vector(typename std::_Vector_val<_Ty, _Ax>::_Alty::size_type, const _Ty&, const typename std::_Vector_val<_Ty, _Ax>::_Alty&) [with _Ty = unsigned int, _Ax = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:2008: instantiated from 'std::_Vb_val<_Alloc>::_Vb_val(typename _Alloc::rebind<std::_Vbase>::other::size_type, bool, _Alloc) [with _Alloc = std::allocator<bool>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:2096: instantiated from 'std::vector<bool, _Alloc>::vector() [with _Alloc = std::allocator<bool>]'
C:/workspace/py-ogre-workspace/ogre/SDK/include/OIS/OISJoyStick.h:70: instantiated from here
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/type_traits:611: error: 'value' is not a member of 'std::tr1::is_enum<unsigned int>'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/xutility: In instantiation of 'std::_Ptr_cat_helper<unsigned int, unsigned int>':
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/memory:611: instantiated from 'void std::_Uninitialized_fill_n(_FwdIt, _Diff, const _Tval*, _Alloc&) [with _FwdIt = unsigned int*, _Diff = unsigned int, _Tval = unsigned int, _Alloc = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:1421: instantiated from 'typename std::_Vector_val<_Ty, _Ax>::_Alty::pointer std::vector<_Ty, _Ax>::_Ufill(typename std::_Vector_val<_Ty, _Ax>::_Alty::pointer, typename std::_Vector_val<_Ty, _Ax>::_Alty::size_type, const _Ty*) [with _Ty = unsigned int, _Ax = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:585: instantiated from 'void std::vector<_Ty, _Ax>::_Construct_n(typename std::_Vector_val<_Ty, _Ax>::_Alty::size_type, const _Ty*) [with _Ty = unsigned int, _Ax = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:530: instantiated from 'std::vector<_Ty, _Ax>::vector(typename std::_Vector_val<_Ty, _Ax>::_Alty::size_type, const _Ty&, const typename std::_Vector_val<_Ty, _Ax>::_Alty&) [with _Ty = unsigned int, _Ax = std::allocator<unsigned int>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:2008: instantiated from 'std::_Vb_val<_Alloc>::_Vb_val(typename _Alloc::rebind<std::_Vbase>::other::size_type, bool, _Alloc) [with _Alloc = std::allocator<bool>]'
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/vector:2096: instantiated from 'std::vector<bool, _Alloc>::vector() [with _Alloc = std::allocator<bool>]'
C:/workspace/py-ogre-workspace/ogre/SDK/include/OIS/OISJoyStick.h:70: instantiated from here
C:/workspace/py-ogre-workspace/gccxml-build/GCC_XML/Support/Vc10/Include/xutility:503: error: 'value' is not a member of 'std::tr1::is_scalar<unsigned int>'


PS: I've also posted this on http://groups.google.com/group/python-o ... 5f186eb6fc weeks ago, but never got a reply.

thios

09-01-2012 19:43:19

It's been a while since I last built python-ogre for windows, so your errors don't ring a bell. But these instructions definitely work, at least for WindowsXP32/VC2008.

Hope that helps...

sybren

23-01-2012 13:04:18

Thanks for the reply. However, the instructions are for Python 2.7 (we use 3.2) and old versions of Visual Studio and Boost::Python. The code we need for Python 3.x support lives on another branch.