[C++-sig] Cplusplus-sig Digest, Vol 30, Issue 6

Ryan Murray rymurr at gmail.com
Wed Mar 9 20:50:25 CET 2011


Hi Austin,

Thanks for the reply. The lines you changed in my compile command were
actually how I was compiling as well. I just copied the wrong line
into the email. On my Linux box the problem was being caused by an old
set of boost libraries compiled with an older intel compiler. On OSX,
I am not certain exactly but it seems that I was linking the module
against a python2.6 library but boost_python had been built with the
2.7 library or there was a mismatch with headers or something else
strange. So I feel much better now that a program I thought should
work does.

One follow up question, if i link the library using
-Wl,-soname,libtest.so then move the file to test.so does that make a
difference when importing and using it?

Thanks for your help,

Ryan


On Tue, Mar 8, 2011 at 11:00 AM,  <cplusplus-sig-request at python.org> wrote:
> Hi Ryan,
>
> I tried out your code (g++, python2.6, boost-1.40) and it worked just
> fine. However, I had to make a few changes to your compilation command
> to get it working. The python module you're defining is called
> "testing", but your command is generating a "libclassical.so"; you
> need to output "testing.so" (no leading 'lib') for python to import
> it/associate it with the module "testing". Is it possible that you're
> actually loading a module from some old build or something?
>
> Other than that, I can't see any problems. Can you possibly post a stack trace?
>
> Austin
>
> On Mon, Mar 7, 2011 at 5:03 PM, Ryan Murray <rymurr at gmail.com> wrote:
>> Hi All,
>>
>> I am testing boost python with the following code:
>>
>>
>> #include <boost/python.hpp>
>> #include <iostream>
>> #include <stdexcept>
>>
>> using namespace boost::python;
>>
>> int pyrun_main();
>>
>> BOOST_PYTHON_MODULE(testing)
>> {
>> ? ?def("pyrun_main",pyrun_main);
>> }
>>
>> int pyrun_main(){
>> ? ?try{
>> ? ? ? ?throw std::exception();
>> ? ?}
>> ? ?catch(std::exception &e){
>> ? ? ? ?std::cout << "fun!" << std::endl;
>> ? ?}
>>
>> ? ?return 1;
>> }
>>
>>
>> I compile it with:
>>
>> g++ boostpy.cpp -I/usr/include/python2.6/ -lpython2.6 -fPIC ? -shared
>> -Wl,-soname,libclassical.so -o libclassical.so
>>
>> and import it into python without problems. When running pyrun_main()
>> I get a Segmentation Fault. and no other useful output. I have tried
>> on python 2.6 and 2.7 on Linux and OSX. And have tried g++,clang,icpc
>> compilers. On boost 1.44,1.45 and 1.46.
>> Perhaps I am missing something very simple but I cant find any reason
>> why this won't run. I have other code that does not throw and works
>> fine.
>>
>> Thanks
>> Ryan
>> _______________________________________________
>> Cplusplus-sig mailing list
>> Cplusplus-sig at python.org
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>


More information about the Cplusplus-sig mailing list