   Python - C/C++
  HiI am quite confused by now and hope that someone may shed some light here...  :)I want to call C/C++ functions from Python. For this I'm cuurrently using the Boost library, but experience "some" trouble with it.I've created a dll and export some functions from it with the BOOST_PYTHON_MODULE() macro. Thereafter I use bjam to compile the project and all seems fine... except that no dll or *.pyd file is created. Since my boost and python experience is yet quite limited I do not know what to do next.* I'm running this on Windows XP* The Boost python examples compile nice with bjam (no dll/pyd here either)* I can compile the dll with visual studio (but then i obviously won't get a pyd file)* In all cases I get a *.obj and *.pyd.rsp so I get the feeling that some kind of "linking" stage is missing.* I have read the Boost/Python docs several times, but I do not get the results that I should.Can someone please tell me the basics mechanisms of the bjam builder and how the rules work in jamfiles. Any comments are appriciated.Thank you// Javelin   
Quote:Original post by Javelin* I can compile the dll with visual studio (but then i obviously won't get a pyd file)This works perfectly fine for me. You need to set the output of the project (Configuration Properties->Linker->General) to a .pyd file. There may be some additional settings you need to set, but I can't think of anything at the moment.   ;  You can use the ctypes package that's included with python version 2.5 instead of boost::python. It's easier in my opinion.   ;Quote:Original post by Omid GhavamiQuote:Original post by Javelin* I can compile the dll with visual studio (but then i obviously won't get a pyd file)This works perfectly fine for me. You need to set the output of the project (Configuration Properties->Linker->General) to a .pyd file. There may be some additional settings you need to set, but I can't think of anything at the moment.So a .pyd is the same as a .dll but with a different name extension? I thought it was a specially processed file to fit with python.(Btw. I graduated from Chalmers in 2003 and now I live nearby. It a small world sometimes...  :) )Quote:Original post by smrYou can use the ctypes package that's included with python version 2.5 instead of boost::python. It's easier in my opinion.Tested it and it seems quite nice, but if I understand things correct I can't use C++ classes with it.What I really would like to have is a transparent mapping between python classes an c++ classes. E.g. if I have a class "foo" in c++ I would like to inherit that class to a python class "bar".So if I make a call in python, I dont need to know if the function is defined in c++ or python. The call just looks the same.It sees that Boost.Python gives me this, but I can't figure out how to build the things together. If anyone has a short example (with code) I really would  appriciate it.Thanks for your answers. At least it incereased my spirits...  ;)// Javelin;  I'm an idiot...  :]Small typo in my build files...Seems to work now...// Javelin   ;Quote:Original post by JavelinQuote:Original post by Omid GhavamiQuote:Original post by Javelin* I can compile the dll with visual studio (but then i obviously won't get a pyd file)This works perfectly fine for me. You need to set the output of the project (Configuration Properties->Linker->General) to a .pyd file. There may be some additional settings you need to set, but I can't think of anything at the moment.So a .pyd is the same as a .dll but with a different name extension? I thought it was a specially processed file to fit with python.I believe so, yes. It is of course different because of the content of the dll, but it's still a Dynamic Type Library. Someone correct me if this is wrong ^^Quote:(Btw. I graduated from Chalmers in 2003 and now I live nearby. It a small world sometimes...  :) )It is indeed [smile] Nice to see other chalmerists around here =)   ;  Which version of Visual Studio are you using?  Just wondering because I had 2005 and downgraded to 2003 just to be able to make python extensions work.  Maybe there is a workaround now but my experience has been VC 2005 does not like python - or maybe its the other way around.For my own python development i write a C API interface into what ever it is I'm using then I can either use PyRex or Swig to access it.   ;Quote:Original post by MrRageJust wondering because I had 2005 and downgraded to 2003 just to be able to make python extensions work.  Maybe there is a workaround now but my experience has been VC 2005 does not like python - or maybe its the other way around.The Python C API is incredibly brittle and hard-coded, including macros offsetting into structs to retrieve data, etc. You therefore have to have everything compiled with the same compiler if you want anything to stand a chance of working without cryptic errors.;  One of the major reasons that pythons built with different compilers are incompatible is that they use FILE* internally, which is of an implementation defined type.   ;Quote:Original post by KylotanThe Python C API is incredibly brittle and hard-coded, including macros offsetting into structs to retrieve data, etc. You therefore have to have everything compiled with the same compiler if you want anything to stand a chance of working without cryptic errors.Oh, wow. No wonder I couldn't get Pygame to install.Are there plans to fix this, either before or in P3K?   