[C++-sig] Using boost::python in an /clr application

Luke Titley luke.titley at naturalmotion.com
Sat Sep 8 12:56:07 CEST 2007

Hey Tom,
I'm having exactly the same problem as you have described in this message.
Were you able to resolve it? If so I would very much like to hear how.
Kind Regards,
Luke Titley
Hi everyone!
I'm embedding a python interpreter in an /clr application using visual 
studio 2005. For the most simple example I created a new CLR console 
application using the visual studio project wizard and added a few lines 
of code resulting in the following .cpp file.
        // CRLConsoleApp.cpp : main project file.
        #include "stdafx.h"
        // include as unmanaged and disable warnings for __fastcall
        #pragma unmanaged
        #pragma warning(disable:4561)
        #include <boost/python.hpp>
        #pragma warning(default:4561)
        #pragma managed
        // just a simple function
        int sampleFunction()
               return 42;
        // initialize a sample modul
        void initSampleModul()
        int main(array<System::String ^> ^args)
            return 0;
This works perfectly fine, I can compile it, I can link it, I can run 
it, I can use the sample function in a python script running in an 
embedded python interpreter.
Exposing a class to python is not working quite as I want it to. I 
change the above .cpp file to include to following lines of code.
        // most simple class to expose to python
        class SampleClass {
        // initialize the sample modul exposing the sample class
        void initSampleModul()
using the above code gives me two linking errors:
error LNK2020: unresolved token (06000007) 
error LNK2020: unresolved token (06000008) 
The version of boost I'm using here is 1.33.1 which was build using the 
VC_80 tools and I'm using Python version 2.5.
The above visual studio project is linked to 
boost_python-vc80-mt-1_33_1.lib and python25.lib
I've done the very same thing (linking to the same .lib files using 
mostly the same code except /clr specific parts) in a win32 console 
application and exposing the sample class to python works as expected. I 
can use the class in my embedded python interpreter....  just doing that 
in an CLR application is not working.
I'm very thankful for any help I can get!
best regards,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070908/5e70d3aa/attachment.htm>

More information about the Cplusplus-sig mailing list