From jonlederman at gmail.com Thu Sep 8 16:29:12 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Thu, 8 Sep 2016 16:29:12 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute Message-ID: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> Hi, I am trying to use Boost Python with a set of classes I am compiling into a library. Call them class A, class B and class C. If I just have class A and I use: BOOST_PYTHON_MODULE(A) and my Makefile builds an executable called A.so I am able to see the classes embedded in the module. However, if I compile to a different .so name, say D.so, I cannot see any of the classes inside my BOOST_PYTHON_MODULE definition. For example, if I wrote: BOOST_PYTHON_MODULE(strategy) { using namespace boost::python; class_("EncoderStrategy", init()) .def("setComplexity", &EncoderStrategy::setComplexity) .def("getComplexity", &EncoderStrategy::getComplexity); } and I compile my code to be in a shared object strategy.so, when I load the class into python, I don?t see the EncoderStrategy class as an attribute of strategy. I have tried to read the docs re: packages and submodules but am unclear how to use them. Ideally, I would like one .so file called strategy.so that encompasses a set of classes. Is there an example or other documentation that would help me here? Thanks. -Jon From stefan at seefeld.name Thu Sep 8 16:47:26 2016 From: stefan at seefeld.name (Stefan Seefeld) Date: Thu, 8 Sep 2016 16:47:26 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> Message-ID: <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Hi Jon, what you are describing makes perfect sense, and should work without problem. From your description it isn't clear why this isn't working, so I suggest you put together a self-contained test that doesn't work as you expect, and send that out so we can have a look. Otherwise we'd have to guess. The online docs at http://boostorg.github.io/python/doc/html/index.html should contain everything you need. Stefan -- ...ich hab' noch einen Koffer in Berlin... From jonlederman at gmail.com Thu Sep 8 17:30:40 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Thu, 8 Sep 2016 17:30:40 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: Hi, Thanks for responding. Here is my header file. I am compiling this to a shared object called opus_strategy.so. If I set the argument of BOOST_PYTHON_MODULE to opus_encoder_strategy, and compile my .so file to have the name opus_encoder_strategy.so,I can load the boost python module into my python interpreter and see the OpusEncoderStrategy class as an attribute. However, if I choose other names such as opus_strategy for the argument to BOOST_PYTHON_MODULE, when I load the boost python object it doesn?t appear to have any recognized attributes. I don?t understand why the name should matter. As I had noted in my previous email, I would like to have a shared object file with the name opus_strategy.so that encompasses a set of classes. Just can?t figure out how to get it to work. I am on OS X, BTW if that matters. Any help would be greatly appreciated. Thanks. -Jon #ifndef OPUS_ENCODER_STRATEGY_H_ #define OPUS_ENCODER_STRATEGY_H_ #include "memory" #include "opus/opus.h" #include "opus/opus_defines.h" #include "opus/opus_multistream.h" #include "opus/opus_types.h" #include #include #include #include #include #include #include namespace bp = boost::python; namespace np = boost::numpy; using namespace std; class OpusEncoderStrategy { public: OpusEncoderStrategy(const int sample_rate, const int number_channels, const int opus_application); ~OpusEncoderStrategy(); opus_int32 encode(const float* pcm, const int frame_size, const unsigned char* data, opus_int32 max_data_bytes); bool setComplexity(const int c); int getComplexity(); private: bool encoderCtl(); int getPacketDurationBytes(); OpusEncoder* encoder; int fs; int channels; int application; int error; }; BOOST_PYTHON_MODULE(opus_strategy) { using namespace boost::python; class_("OpusEncoderStrategy", init()) .def("setComplexity", &OpusEncoderStrategy::setComplexity) .def("getComplexity", &OpusEncoderStrategy::getComplexity); } #endif > On Sep 8, 2016, at 4:47 PM, Stefan Seefeld wrote: > > Hi Jon, > > what you are describing makes perfect sense, and should work without > problem. From your description it isn't clear why this isn't working, so > I suggest you put together a self-contained test that doesn't work as > you expect, and send that out so we can have a look. Otherwise we'd have > to guess. > The online docs at http://boostorg.github.io/python/doc/html/index.html > should contain everything you need. > > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig From stefan at seefeld.name Thu Sep 8 18:00:09 2016 From: stefan at seefeld.name (Stefan Seefeld) Date: Thu, 8 Sep 2016 18:00:09 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: Hi Jon, please remove the dependency on the "opus/*" headers, so we can compile the module ourselves and try to reproduce what you are reporting. (That's what I meant with "self-contained test".) Thanks, Stefan On 08.09.2016 17:30, Jon Lederman wrote: > Hi, > > Thanks for responding. Here is my header file. I am compiling this to a shared object called opus_strategy.so. If I set the argument of BOOST_PYTHON_MODULE to opus_encoder_strategy, and compile my .so file to have the name opus_encoder_strategy.so,I can load the boost python module into my python interpreter and see the OpusEncoderStrategy class as an attribute. > > However, if I choose other names such as opus_strategy for the argument to BOOST_PYTHON_MODULE, when I load the boost python object it doesn?t appear to have any recognized attributes. I don?t understand why the name should matter. As I had noted in my previous email, I would like to have a shared object file with the name opus_strategy.so that encompasses a set of classes. Just can?t figure out how to get it to work. I am on OS X, BTW if that matters. > > Any help would be greatly appreciated. > > Thanks. > > -Jon > #ifndef OPUS_ENCODER_STRATEGY_H_ > #define OPUS_ENCODER_STRATEGY_H_ > > > > > > #include "memory" > #include "opus/opus.h" > #include "opus/opus_defines.h" > #include "opus/opus_multistream.h" > #include "opus/opus_types.h" > > #include > #include > #include > #include > #include > #include > #include > > namespace bp = boost::python; > namespace np = boost::numpy; > > using namespace std; > > > class OpusEncoderStrategy { > > public: > > OpusEncoderStrategy(const int sample_rate, const int number_channels, const int opus_application); > ~OpusEncoderStrategy(); > > opus_int32 encode(const float* pcm, const int frame_size, const unsigned char* data, opus_int32 max_data_bytes); > > bool setComplexity(const int c); > int getComplexity(); > > > private: > > bool encoderCtl(); > int getPacketDurationBytes(); > > > > OpusEncoder* encoder; > > int fs; > int channels; > int application; > int error; > > > }; > > > BOOST_PYTHON_MODULE(opus_strategy) > { > using namespace boost::python; > > > class_("OpusEncoderStrategy", init()) > .def("setComplexity", &OpusEncoderStrategy::setComplexity) > .def("getComplexity", &OpusEncoderStrategy::getComplexity); > } > > > #endif >> On Sep 8, 2016, at 4:47 PM, Stefan Seefeld wrote: >> >> Hi Jon, >> >> what you are describing makes perfect sense, and should work without >> problem. From your description it isn't clear why this isn't working, so >> I suggest you put together a self-contained test that doesn't work as >> you expect, and send that out so we can have a look. Otherwise we'd have >> to guess. >> The online docs at http://boostorg.github.io/python/doc/html/index.html >> should contain everything you need. >> >> Stefan >> >> -- >> >> ...ich hab' noch einen Koffer in Berlin... >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> https://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig -- ...ich hab' noch einen Koffer in Berlin... From jonlederman at gmail.com Thu Sep 8 18:33:29 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Thu, 8 Sep 2016 18:33:29 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: <1EC03BFD-C05E-43B6-8F4B-385EFD70B71D@gmail.com> Hi, Ok. I have removed all the opus library dependencies and stripped away much of everything else. It seems to me that the name of the generated .so has to match the name of the module. Perhaps I am building incorrectly. I am using make. -Jon #ifndef OPUS_ENCODER_STRATEGY_H_ #define OPUS_ENCODER_STRATEGY_H_ #include "memory" #include #include #include #include #include #include #include namespace bp = boost::python; namespace np = boost::numpy; using namespace std; class OpusEncoderStrategy { public: OpusEncoderStrategy(){}; ~OpusEncoderStrategy(){}; int fs; int channels; int application; int error; }; BOOST_PYTHON_MODULE(opus_strategy) { using namespace boost::python; class_("OpusEncoderStrategy", init()); } #endif > On Sep 8, 2016, at 6:00 PM, Stefan Seefeld wrote: > > Hi Jon, > > please remove the dependency on the "opus/*" headers, so we can compile > the module ourselves and try to reproduce what you are reporting. > (That's what I meant with "self-contained test".) > > > Thanks, > Stefan > > On 08.09.2016 17:30, Jon Lederman wrote: >> Hi, >> >> Thanks for responding. Here is my header file. I am compiling this to a shared object called opus_strategy.so. If I set the argument of BOOST_PYTHON_MODULE to opus_encoder_strategy, and compile my .so file to have the name opus_encoder_strategy.so,I can load the boost python module into my python interpreter and see the OpusEncoderStrategy class as an attribute. >> >> However, if I choose other names such as opus_strategy for the argument to BOOST_PYTHON_MODULE, when I load the boost python object it doesn?t appear to have any recognized attributes. I don?t understand why the name should matter. As I had noted in my previous email, I would like to have a shared object file with the name opus_strategy.so that encompasses a set of classes. Just can?t figure out how to get it to work. I am on OS X, BTW if that matters. >> >> Any help would be greatly appreciated. >> >> Thanks. >> >> -Jon >> #ifndef OPUS_ENCODER_STRATEGY_H_ >> #define OPUS_ENCODER_STRATEGY_H_ >> >> >> >> >> >> #include "memory" >> #include "opus/opus.h" >> #include "opus/opus_defines.h" >> #include "opus/opus_multistream.h" >> #include "opus/opus_types.h" >> >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> >> namespace bp = boost::python; >> namespace np = boost::numpy; >> >> using namespace std; >> >> >> class OpusEncoderStrategy { >> >> public: >> >> OpusEncoderStrategy(const int sample_rate, const int number_channels, const int opus_application); >> ~OpusEncoderStrategy(); >> >> opus_int32 encode(const float* pcm, const int frame_size, const unsigned char* data, opus_int32 max_data_bytes); >> >> bool setComplexity(const int c); >> int getComplexity(); >> >> >> private: >> >> bool encoderCtl(); >> int getPacketDurationBytes(); >> >> >> >> OpusEncoder* encoder; >> >> int fs; >> int channels; >> int application; >> int error; >> >> >> }; >> >> >> BOOST_PYTHON_MODULE(opus_strategy) >> { >> using namespace boost::python; >> >> >> class_("OpusEncoderStrategy", init()) >> .def("setComplexity", &OpusEncoderStrategy::setComplexity) >> .def("getComplexity", &OpusEncoderStrategy::getComplexity); >> } >> >> >> #endif >>> On Sep 8, 2016, at 4:47 PM, Stefan Seefeld wrote: >>> >>> Hi Jon, >>> >>> what you are describing makes perfect sense, and should work without >>> problem. From your description it isn't clear why this isn't working, so >>> I suggest you put together a self-contained test that doesn't work as >>> you expect, and send that out so we can have a look. Otherwise we'd have >>> to guess. >>> The online docs at http://boostorg.github.io/python/doc/html/index.html >>> should contain everything you need. >>> >>> Stefan >>> >>> -- >>> >>> ...ich hab' noch einen Koffer in Berlin... >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> https://mail.python.org/mailman/listinfo/cplusplus-sig >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> https://mail.python.org/mailman/listinfo/cplusplus-sig > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig From jonlederman at gmail.com Thu Sep 8 19:38:54 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Thu, 8 Sep 2016 19:38:54 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: <1EC03BFD-C05E-43B6-8F4B-385EFD70B71D@gmail.com> References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> <1EC03BFD-C05E-43B6-8F4B-385EFD70B71D@gmail.com> Message-ID: Hi, I think this text on this page: https://www.preney.ca/paul/archives/107 relates to the issue I?m having: It is very important that "libyay" in BOOST_PYTHON_MODULE(libyay) matches the name of the library you're generating in CMakeLists.txt (without the extension). NOTE: On Linux / Unix systems you will need to prefix the name with "lib" as CMake defaults to prepending the file with "lib" as per convention on Linux / Unix systems. Essentially, the BOOST_PYTHON_MODULE clause exports the "yay" function as the Python symbol name "yay". This will allow you to call the "yay" function from Python later. > On Sep 8, 2016, at 6:33 PM, Jon Lederman wrote: > > Hi, > > Ok. I have removed all the opus library dependencies and stripped away much of everything else. It seems to me that the name of the generated .so has to match the name of the module. Perhaps I am building incorrectly. I am using make. > > > > -Jon > > #ifndef OPUS_ENCODER_STRATEGY_H_ > #define OPUS_ENCODER_STRATEGY_H_ > > #include "memory" > #include > #include > #include > #include > #include > #include > #include > > namespace bp = boost::python; > namespace np = boost::numpy; > > using namespace std; > > > class OpusEncoderStrategy { > > public: > > OpusEncoderStrategy(){}; > ~OpusEncoderStrategy(){}; > > int fs; > int channels; > int application; > int error; > > > }; > > > BOOST_PYTHON_MODULE(opus_strategy) > { > using namespace boost::python; > > class_("OpusEncoderStrategy", init()); > } > > > #endif >> On Sep 8, 2016, at 6:00 PM, Stefan Seefeld wrote: >> >> Hi Jon, >> >> please remove the dependency on the "opus/*" headers, so we can compile >> the module ourselves and try to reproduce what you are reporting. >> (That's what I meant with "self-contained test".) >> >> >> Thanks, >> Stefan >> >> On 08.09.2016 17:30, Jon Lederman wrote: >>> Hi, >>> >>> Thanks for responding. Here is my header file. I am compiling this to a shared object called opus_strategy.so. If I set the argument of BOOST_PYTHON_MODULE to opus_encoder_strategy, and compile my .so file to have the name opus_encoder_strategy.so,I can load the boost python module into my python interpreter and see the OpusEncoderStrategy class as an attribute. >>> >>> However, if I choose other names such as opus_strategy for the argument to BOOST_PYTHON_MODULE, when I load the boost python object it doesn?t appear to have any recognized attributes. I don?t understand why the name should matter. As I had noted in my previous email, I would like to have a shared object file with the name opus_strategy.so that encompasses a set of classes. Just can?t figure out how to get it to work. I am on OS X, BTW if that matters. >>> >>> Any help would be greatly appreciated. >>> >>> Thanks. >>> >>> -Jon >>> #ifndef OPUS_ENCODER_STRATEGY_H_ >>> #define OPUS_ENCODER_STRATEGY_H_ >>> >>> >>> >>> >>> >>> #include "memory" >>> #include "opus/opus.h" >>> #include "opus/opus_defines.h" >>> #include "opus/opus_multistream.h" >>> #include "opus/opus_types.h" >>> >>> #include >>> #include >>> #include >>> #include >>> #include >>> #include >>> #include >>> >>> namespace bp = boost::python; >>> namespace np = boost::numpy; >>> >>> using namespace std; >>> >>> >>> class OpusEncoderStrategy { >>> >>> public: >>> >>> OpusEncoderStrategy(const int sample_rate, const int number_channels, const int opus_application); >>> ~OpusEncoderStrategy(); >>> >>> opus_int32 encode(const float* pcm, const int frame_size, const unsigned char* data, opus_int32 max_data_bytes); >>> >>> bool setComplexity(const int c); >>> int getComplexity(); >>> >>> >>> private: >>> >>> bool encoderCtl(); >>> int getPacketDurationBytes(); >>> >>> >>> >>> OpusEncoder* encoder; >>> >>> int fs; >>> int channels; >>> int application; >>> int error; >>> >>> >>> }; >>> >>> >>> BOOST_PYTHON_MODULE(opus_strategy) >>> { >>> using namespace boost::python; >>> >>> >>> class_("OpusEncoderStrategy", init()) >>> .def("setComplexity", &OpusEncoderStrategy::setComplexity) >>> .def("getComplexity", &OpusEncoderStrategy::getComplexity); >>> } >>> >>> >>> #endif >>>> On Sep 8, 2016, at 4:47 PM, Stefan Seefeld wrote: >>>> >>>> Hi Jon, >>>> >>>> what you are describing makes perfect sense, and should work without >>>> problem. From your description it isn't clear why this isn't working, so >>>> I suggest you put together a self-contained test that doesn't work as >>>> you expect, and send that out so we can have a look. Otherwise we'd have >>>> to guess. >>>> The online docs at http://boostorg.github.io/python/doc/html/index.html >>>> should contain everything you need. >>>> >>>> Stefan >>>> >>>> -- >>>> >>>> ...ich hab' noch einen Koffer in Berlin... >>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> https://mail.python.org/mailman/listinfo/cplusplus-sig >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> https://mail.python.org/mailman/listinfo/cplusplus-sig >> >> >> -- >> >> ...ich hab' noch einen Koffer in Berlin... >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> https://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonlederman at gmail.com Thu Sep 8 19:44:04 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Thu, 8 Sep 2016 19:44:04 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: For example in this example, does the name of my shared object file (.so) need to be zoo.so in order to see the attribute Animal? I am very confused about all of this. /* * This inclusion should be put at the beginning. It will include . */ #include #include #include #include #include #include /* * This is the C++ function we write and want to expose to Python. */ const std::string hello() { return std::string("hello, zoo"); } /* * Create a C++ class to represent animals in the zoo. */ class Animal { public: // Constructor. Note no default constructor is defined. Animal(std::string const & in_name): m_name(in_name) {} // Copy constructor. Animal(Animal const & in_other): m_name(in_other.m_name) {} // Copy assignment. Animal & operator=(Animal const & in_other) { this->m_name = in_other.m_name; return *this; } // Utility method to get the address of the instance. uintptr_t get_address() const { return reinterpret_cast(this); } // Getter of the name property. std::string get_name() const { return this->m_name; } // Setter of the name property. void set_name(std::string const & in_name) { this->m_name = in_name; } private: // The only property: the name of the animal. std::string m_name; }; /* * This is a macro Boost.Python provides to signify a Python extension module. */ BOOST_PYTHON_MODULE(zoo) { // An established convention for using boost.python. using namespace boost::python; // Expose the function hello(). def("hello", hello); // Expose the class Animal. class_("Animal", init()) .def("get_address", &Animal::get_address) .add_property("name", &Animal::get_name, &Animal::set_name) ; } // vim: set ai et nu sw=4 ts=4 tw=79: > On Sep 8, 2016, at 6:00 PM, Stefan Seefeld wrote: > > Hi Jon, > > please remove the dependency on the "opus/*" headers, so we can compile > the module ourselves and try to reproduce what you are reporting. > (That's what I meant with "self-contained test".) > > > Thanks, > Stefan > > On 08.09.2016 17:30, Jon Lederman wrote: >> Hi, >> >> Thanks for responding. Here is my header file. I am compiling this to a shared object called opus_strategy.so. If I set the argument of BOOST_PYTHON_MODULE to opus_encoder_strategy, and compile my .so file to have the name opus_encoder_strategy.so,I can load the boost python module into my python interpreter and see the OpusEncoderStrategy class as an attribute. >> >> However, if I choose other names such as opus_strategy for the argument to BOOST_PYTHON_MODULE, when I load the boost python object it doesn?t appear to have any recognized attributes. I don?t understand why the name should matter. As I had noted in my previous email, I would like to have a shared object file with the name opus_strategy.so that encompasses a set of classes. Just can?t figure out how to get it to work. I am on OS X, BTW if that matters. >> >> Any help would be greatly appreciated. >> >> Thanks. >> >> -Jon >> #ifndef OPUS_ENCODER_STRATEGY_H_ >> #define OPUS_ENCODER_STRATEGY_H_ >> >> >> >> >> >> #include "memory" >> #include "opus/opus.h" >> #include "opus/opus_defines.h" >> #include "opus/opus_multistream.h" >> #include "opus/opus_types.h" >> >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> >> namespace bp = boost::python; >> namespace np = boost::numpy; >> >> using namespace std; >> >> >> class OpusEncoderStrategy { >> >> public: >> >> OpusEncoderStrategy(const int sample_rate, const int number_channels, const int opus_application); >> ~OpusEncoderStrategy(); >> >> opus_int32 encode(const float* pcm, const int frame_size, const unsigned char* data, opus_int32 max_data_bytes); >> >> bool setComplexity(const int c); >> int getComplexity(); >> >> >> private: >> >> bool encoderCtl(); >> int getPacketDurationBytes(); >> >> >> >> OpusEncoder* encoder; >> >> int fs; >> int channels; >> int application; >> int error; >> >> >> }; >> >> >> BOOST_PYTHON_MODULE(opus_strategy) >> { >> using namespace boost::python; >> >> >> class_("OpusEncoderStrategy", init()) >> .def("setComplexity", &OpusEncoderStrategy::setComplexity) >> .def("getComplexity", &OpusEncoderStrategy::getComplexity); >> } >> >> >> #endif >>> On Sep 8, 2016, at 4:47 PM, Stefan Seefeld wrote: >>> >>> Hi Jon, >>> >>> what you are describing makes perfect sense, and should work without >>> problem. From your description it isn't clear why this isn't working, so >>> I suggest you put together a self-contained test that doesn't work as >>> you expect, and send that out so we can have a look. Otherwise we'd have >>> to guess. >>> The online docs at http://boostorg.github.io/python/doc/html/index.html >>> should contain everything you need. >>> >>> Stefan >>> >>> -- >>> >>> ...ich hab' noch einen Koffer in Berlin... >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> https://mail.python.org/mailman/listinfo/cplusplus-sig >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> https://mail.python.org/mailman/listinfo/cplusplus-sig > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonlederman at gmail.com Thu Sep 8 20:33:57 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Thu, 8 Sep 2016 20:33:57 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: Hi, And here is yet another person who seems to encounter the same issue: http://stackoverflow.com/questions/9140572/c-boost-python-2-problems -Jon > On Sep 8, 2016, at 6:00 PM, Stefan Seefeld wrote: > > Hi Jon, > > please remove the dependency on the "opus/*" headers, so we can compile > the module ourselves and try to reproduce what you are reporting. > (That's what I meant with "self-contained test".) > > > Thanks, > Stefan > > On 08.09.2016 17:30, Jon Lederman wrote: >> Hi, >> >> Thanks for responding. Here is my header file. I am compiling this to a shared object called opus_strategy.so. If I set the argument of BOOST_PYTHON_MODULE to opus_encoder_strategy, and compile my .so file to have the name opus_encoder_strategy.so,I can load the boost python module into my python interpreter and see the OpusEncoderStrategy class as an attribute. >> >> However, if I choose other names such as opus_strategy for the argument to BOOST_PYTHON_MODULE, when I load the boost python object it doesn?t appear to have any recognized attributes. I don?t understand why the name should matter. As I had noted in my previous email, I would like to have a shared object file with the name opus_strategy.so that encompasses a set of classes. Just can?t figure out how to get it to work. I am on OS X, BTW if that matters. >> >> Any help would be greatly appreciated. >> >> Thanks. >> >> -Jon >> #ifndef OPUS_ENCODER_STRATEGY_H_ >> #define OPUS_ENCODER_STRATEGY_H_ >> >> >> >> >> >> #include "memory" >> #include "opus/opus.h" >> #include "opus/opus_defines.h" >> #include "opus/opus_multistream.h" >> #include "opus/opus_types.h" >> >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> >> namespace bp = boost::python; >> namespace np = boost::numpy; >> >> using namespace std; >> >> >> class OpusEncoderStrategy { >> >> public: >> >> OpusEncoderStrategy(const int sample_rate, const int number_channels, const int opus_application); >> ~OpusEncoderStrategy(); >> >> opus_int32 encode(const float* pcm, const int frame_size, const unsigned char* data, opus_int32 max_data_bytes); >> >> bool setComplexity(const int c); >> int getComplexity(); >> >> >> private: >> >> bool encoderCtl(); >> int getPacketDurationBytes(); >> >> >> >> OpusEncoder* encoder; >> >> int fs; >> int channels; >> int application; >> int error; >> >> >> }; >> >> >> BOOST_PYTHON_MODULE(opus_strategy) >> { >> using namespace boost::python; >> >> >> class_("OpusEncoderStrategy", init()) >> .def("setComplexity", &OpusEncoderStrategy::setComplexity) >> .def("getComplexity", &OpusEncoderStrategy::getComplexity); >> } >> >> >> #endif >>> On Sep 8, 2016, at 4:47 PM, Stefan Seefeld wrote: >>> >>> Hi Jon, >>> >>> what you are describing makes perfect sense, and should work without >>> problem. From your description it isn't clear why this isn't working, so >>> I suggest you put together a self-contained test that doesn't work as >>> you expect, and send that out so we can have a look. Otherwise we'd have >>> to guess. >>> The online docs at http://boostorg.github.io/python/doc/html/index.html >>> should contain everything you need. >>> >>> Stefan >>> >>> -- >>> >>> ...ich hab' noch einen Koffer in Berlin... >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> https://mail.python.org/mailman/listinfo/cplusplus-sig >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> https://mail.python.org/mailman/listinfo/cplusplus-sig > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig From Holger.Joukl at LBBW.de Fri Sep 9 04:07:58 2016 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Fri, 9 Sep 2016 10:07:58 +0200 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: Hi, "Cplusplus-sig" schrieb am 09.09.2016 02:33:57: > Hi, > > And here is yet another person who seems to encounter the same issue: > http://stackoverflow.com/questions/9140572/c-boost-python-2-problems > > -Jon Python expects an init function for extension modules named initNAME where NAME is the name of the extension module, i.e. NAME.so. (see https://docs.python.org/2/extending/extending.html) BOOST_PYTHON_MODULE is boost.python's macro for automagically giving you such an init function. So in the directives - in the boost.python wrapper code: BOOST_PYTHON_MODULE(NAME) - in the Jamroot file: python-extension NAME (or maybe if you compile without bjam, in your g++ link step the -o Parameter: g++ -shared -oNAME.so -Wl,-h -Wl,NAME.so ... # don't know if the SONAME setting (-Wl,-h -Wl,NAME.so) must also match as # Python dlopen()s the extension) NAME must be consistent. Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart From jonlederman at gmail.com Fri Sep 9 09:29:41 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Fri, 9 Sep 2016 09:29:41 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: Hi, Thanks for the response. However, this example doesn?t work for me either if I set the shared object file to zoo.so. It doesn?t find the animal attribute: http://pyengr.readthedocs.io/en/latest/inter/bpy Can you explain why? Thanks. Jon > On Sep 9, 2016, at 4:07 AM, Holger Joukl wrote: > > Hi, > > "Cplusplus-sig" > schrieb am 09.09.2016 02:33:57: > >> Hi, >> >> And here is yet another person who seems to encounter the same issue: >> http://stackoverflow.com/questions/9140572/c-boost-python-2-problems >> >> -Jon > > Python expects an init function for extension modules named initNAME > where NAME is the name of the extension module, i.e. NAME.so. > (see https://docs.python.org/2/extending/extending.html) > > BOOST_PYTHON_MODULE is boost.python's macro for automagically giving you > such > an init function. > > So in the directives > - in the boost.python wrapper code: BOOST_PYTHON_MODULE(NAME) > - in the Jamroot file: python-extension NAME > (or maybe if you compile without bjam, in your g++ link step the -o > Parameter: > g++ -shared -oNAME.so -Wl,-h -Wl,NAME.so ... > # don't know if the SONAME setting (-Wl,-h -Wl,NAME.so) must also match as > # Python dlopen()s the extension) > > NAME must be consistent. > > Holger > > Landesbank Baden-Wuerttemberg > Anstalt des oeffentlichen Rechts > Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz > HRA 12704 > Amtsgericht Stuttgart > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig From stefan at seefeld.name Fri Sep 9 09:42:17 2016 From: stefan at seefeld.name (Stefan Seefeld) Date: Fri, 9 Sep 2016 09:42:17 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: <80b35bbe-c6fe-d959-2a0a-f007e7736b58@seefeld.name> On 09.09.2016 09:29, Jon Lederman wrote: > Hi, > > Thanks for the response. However, this example doesn?t work for me either if I set the shared object file to zoo.so. It doesn?t find the animal attribute: > > http://pyengr.readthedocs.io/en/latest/inter/bpy > > Can you explain why? It's impossible to help you with so few details. Please describe *exactly* what you are doing. As I suggested already, the easiest thing is to come up with a minimal self-contained test case, then describe in detail how you compile it (what platform, what compiler command, etc.) so we can attempt to reproduce your observations. Stefan -- ...ich hab' noch einen Koffer in Berlin... From jonlederman at gmail.com Fri Sep 9 10:00:32 2016 From: jonlederman at gmail.com (Jon Lederman) Date: Fri, 9 Sep 2016 10:00:32 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> Message-ID: <0F6B9123-D8C4-47E2-96F7-B3DA7991E06E@gmail.com> Hi, Let me be more explicit: If my BOOST thing is: BOOST_PYTHON_MODULE(opus_encoder_strategy) and my Makefile is like this: all: opus_encoder_strategy.so opus_encoder_strategy.so: opus_encoder_strategy.o ${CC} ${CInc} ${CLinkFlags} $^ -o $@ opus_encoder_strategy.o: opus_encoder_strategy.cpp ${CC} ${CFLAGS} ${CInc} opus_encoder_strategy.cpp -o opus_encoder_strategy.o and I build the name of the .so file to be opus_encoder_strategy.so, then I am able to access the embedded class. HOWEVER, if I change the BOOST thing to BOOST_PYTHON_MODULE(opus_strategy) and my make file to this: all: opus_strategy.so #lv2strategy.so opus_strategy.so: opus_strategy.o ${CC} ${CInc} ${CLinkFlags} $^ -o $@ opus_strategy.o: opus_encoder_strategy.cpp ${CC} ${CFLAGS} ${CInc} opus_encoder_strategy.cpp -o opus_strategy.o it doesn?t work. NOTE that I am matching the BOOST thing to the name of the .so file, this case opus_strategy.so It seems that it is looking at something else like the actual name of the cpp file or cpp file? This makes no sense to me and there is no documentation on how to properly use this. I am using python 3. Is this an issue. The documentation needs substantial improvement and clarification. Please advise ASAP. -Jon > On Sep 9, 2016, at 4:07 AM, Holger Joukl wrote: > > Hi, > > "Cplusplus-sig" > schrieb am 09.09.2016 02:33:57: > >> Hi, >> >> And here is yet another person who seems to encounter the same issue: >> http://stackoverflow.com/questions/9140572/c-boost-python-2-problems >> >> -Jon > > Python expects an init function for extension modules named initNAME > where NAME is the name of the extension module, i.e. NAME.so. > (see https://docs.python.org/2/extending/extending.html) > > BOOST_PYTHON_MODULE is boost.python's macro for automagically giving you > such > an init function. > > So in the directives > - in the boost.python wrapper code: BOOST_PYTHON_MODULE(NAME) > - in the Jamroot file: python-extension NAME > (or maybe if you compile without bjam, in your g++ link step the -o > Parameter: > g++ -shared -oNAME.so -Wl,-h -Wl,NAME.so ... > # don't know if the SONAME setting (-Wl,-h -Wl,NAME.so) must also match as > # Python dlopen()s the extension) > > NAME must be consistent. > > Holger > > Landesbank Baden-Wuerttemberg > Anstalt des oeffentlichen Rechts > Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz > HRA 12704 > Amtsgericht Stuttgart > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig From stefan at seefeld.name Fri Sep 9 10:12:50 2016 From: stefan at seefeld.name (Stefan Seefeld) Date: Fri, 9 Sep 2016 10:12:50 -0400 Subject: [C++-sig] Boost Python Question - Multiple Classes and Modules not appearing as attribute In-Reply-To: <0F6B9123-D8C4-47E2-96F7-B3DA7991E06E@gmail.com> References: <2DBB71F1-A40A-45D7-A9F5-42755F3C4469@gmail.com> <53dcda2f-fc7b-1a03-3994-7a28cfe5be30@seefeld.name> <0F6B9123-D8C4-47E2-96F7-B3DA7991E06E@gmail.com> Message-ID: <1d34aa26-55c1-c8f6-8beb-b81b6cb25b44@seefeld.name> On 09.09.2016 10:00, Jon Lederman wrote: > Hi, > > Let me be more explicit: > > If my BOOST thing is: BOOST_PYTHON_MODULE(opus_encoder_strategy) and my Makefile is like this: > > all: opus_encoder_strategy.so > > opus_encoder_strategy.so: opus_encoder_strategy.o > ${CC} ${CInc} ${CLinkFlags} $^ -o $@ > > > opus_encoder_strategy.o: opus_encoder_strategy.cpp > ${CC} ${CFLAGS} ${CInc} opus_encoder_strategy.cpp -o opus_encoder_strategy.o > > and I build the name of the .so file to be opus_encoder_strategy.so, then I am able to access the embedded class. > > HOWEVER, if I change the BOOST thing to BOOST_PYTHON_MODULE(opus_strategy) and my make file to this: > > all: opus_strategy.so #lv2strategy.so > > > opus_strategy.so: opus_strategy.o > ${CC} ${CInc} ${CLinkFlags} $^ -o $@ > > > opus_strategy.o: opus_encoder_strategy.cpp > ${CC} ${CFLAGS} ${CInc} opus_encoder_strategy.cpp -o opus_strategy.o > > it doesn?t work. > > NOTE that I am matching the BOOST thing to the name of the .so file, this case opus_strategy.so > > It seems that it is looking at something else like the actual name of the cpp file or cpp file? This makes no sense to me and there is no documentation on how to properly use this. > I am using python 3. Is this an issue. The documentation needs substantial improvement and clarification. The name of the original source file is indeed irrelevant. The symptom you describe seems to suggest that the Python interpreter is getting confused. Are you sure the it sees the correct module at all ? (Does the `__file__` attribute look correct ?) Perhaps you have also a 'opus_strategy.py' file in your path so your extension module isn't loaded at all after the renaming ? (Note that the exercise of putting together a minimal self-contained test case, which I've been trying to suggest (still in vain, it seems), would allow you to eliminate any such issues. All it requires is a bit of debugging discipline...) Stefan -- ...ich hab' noch einen Koffer in Berlin...