Import of generated forced python extension fails when external libs / python / example

I am using an Ubuntu based distribution (Elementary OS Loki) and am trying to create the current python extension for hello world from a .cpp file, in a different directory than the one installed in Boost. My Boost version is boost_1_63_0.

I am new to Boost. I was able to run the hello world example from the Boost / python / example / tutorial Boost directory. I call bjam, it generates a .so and I can import the generated library into Python3.5.

When I copy the .cpp to another directory outside of the Boost installation directory, it doesn't work like this. The build using bjam works great, but when I try to import the generated module in python3.5 it gives an ImportError:$PWD/hello_ext.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv

This is the output when running bjam -debug-configuration:

notice: found boost-build.jam at /home/bianca/Documents/programs/boost_1_63_0/boost-build.jam
notice: loading Boost.Build from /home/bianca/Documents/programs/boost_1_63_0/tools/build/src
notice: Searching '/etc' '/home/bianca' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src' '/home/bianca/Documents/programs/boost_1_63_0/tools' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/kernel' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/util' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/build' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/tools' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/contrib' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/.' for site-config configuration file 'site-config.jam'.
notice: Configuration file 'site-config.jam' not found in '/etc' '/home/bianca' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src' '/home/bianca/Documents/programs/boost_1_63_0/tools' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/kernel' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/util' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/build' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/tools' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/contrib' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/.'.
notice: Searching '/home/bianca' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src' '/home/bianca/Documents/programs/boost_1_63_0/tools' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/kernel' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/util' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/build' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/tools' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/contrib' '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src/.' for user-config configuration file 'user-config.jam'.
notice: Loading user-config configuration file 'user-config.jam' from '/home/bianca/Documents/programs/boost_1_63_0/tools/build/src'.
notice: will use 'g++' for gcc, condition <toolset>gcc-5.4
notice: using gcc libraries :: <toolset>gcc-5.4 :: /usr/bin /usr/lib /usr/lib32 /usr/lib64
notice: using gcc archiver :: <toolset>gcc-5.4 :: /usr/bin/ar
notice: using gcc ranlib :: <toolset>gcc-5.4 :: /usr/bin/ranlib
warning: toolset gcc initialization: can not find tool windres
warning: initialized from /home/bianca/Documents/programs/boost_1_63_0/tools/build/src/user-config.jam:45
notice: using rc compiler :: <toolset>gcc-5.4 :: /usr/bin/as
notice: [python-cfg] Configuring python...
notice: [python-cfg]   user-specified version: "3.5"
notice: [python-cfg]   user-specified cmd-or-prefix: "/usr/bin/python3"
notice: [python-cfg]   user-specified includes: "/usr/include/python3.5"
notice: [python-cfg]   user-specified libraries: "/usr/lib"
notice: [python-cfg] Details of this Python configuration:
notice: [python-cfg]   interpreter command: "/usr/bin/python3"
notice: [python-cfg]   include path: "/usr/include/python3.5"
notice: [python-cfg]   library path: "/usr/lib"
notice: [python-cfg] Checking for NumPy...
notice: [python-cfg] running command '/usr/bin/python3 -c "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())"'
notice: [python-cfg] NumPy disabled. Reason:
notice: [python-cfg]   /usr/bin/python3 -c "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())" aborted with 
notice: [python-cfg]   Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'numpy'
...found 10 targets...

      

In the current directory, I have the same .cpp file as in libs / python / example / tutorial / and Jamroot, which contains:

import python ;

if ! [ python.configured ]
{
  ECHO "warning: no Python configured in user-config.jam" ;
  ECHO "warning: will use default configuration" ;
  using python ;
}

# Adjust the following if Boost.Python isn't installed in a default
# location
lib boost_python ;

python-extension hello_ext : hello.cpp ;

      

My user-config.jam file is located in tools / build / src and contains gcc using gcc : 5.4 : g++ ;

config and python configusing python : 3.5 : /usr/bin/python3 : /usr/include/python3.5 : /usr/lib ;

Any thoughts on why this fails?

+3


source to share





All Articles