boostorg / boostorg/python

neither Debian/Ubuntu 1.63 packages nor CMake feature NumPy support (discussion, not a bug)

Aberta
#101 10 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
C++
Estrelas
537
Forks
223
Merge médio
11h 22min
PRs com merge (30d)
2

Descrição

Excuse me for posting here as it is likely a packaging problem, yet I thought I could get some hints here before proceeding with a Debian bug report.

Trying to use the new NumPy support, I came up with the following partial hello world code which compiles, links but fails with an undefined symbol error at runtime:

*hello.cpp*:
```C++
#include

void init()
{
Py_Initialize();
boost::python::numpy::initialize();
}

BOOST_PYTHON_MODULE(hello)
{
}
```

*CMakeLists.txt*:
```CMake
project(hello CXX)
cmake_minimum_required(VERSION 3.7)

add_library(hello SHARED hello.cpp)
set_target_properties(hello PROPERTIES SUFFIX ".so") # e.g. Mac defaults to .dylib which is not looked for by Python

# informing the Python bindings where to find Python
find_package(PythonInterp REQUIRED)
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
target_include_directories(hello PUBLIC ${PYTHON_INCLUDE_DIRS})
target_link_libraries(hello ${PYTHON_LIBRARIES})

# informing the Python bindings where to find Boost.Python
# NumPy support was introduced in 1.63
find_package(Boost 1.63 COMPONENTS python-py${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR} QUIET REQUIRED)
target_link_libraries(hello ${Boost_LIBRARIES})
target_include_directories(hello PUBLIC ${Boost_INCLUDE_DIRS})
```

Here's what happens on a all-standard Ubuntu zesty installation with the Debian/Ubuntu 1.63 packages:

```
$ mkdir build
$ cd build/
$ cmake ..
-- The CXX compiler identification is GNU 4.9.2
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python (found version "2.7.13")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.13")
CMake Warning at /usr/share/cmake-3.7/Modules/FindBoost.cmake:1534 (message):
No header defined for python-py27; skipping header check
Call Stack (most recent call first):
CMakeLists.txt:16 (find_package)

-- Configuring done
-- Generating done
-- Build files have been written to: /home/vagrant/temp/build
$ make
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
[100%] Linking CXX shared library libhello.so
[100%] Built target hello
$ python
Python 2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170118] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libhello
Traceback (most recent call last):
File "", line 1, in
ImportError: ./libhello.so: undefined symbol: _ZN5boost6python5numpy10initializeEb
>>>
```

Also:
```
$ ldd libhello.so
linux-vdso.so.1 => (0x00007ffd301d5000)
libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f2c04b3b000)
libboost_python-py27.so.1.63.0 => /usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.63.0 (0x00007f2c048f2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2c0452b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2c0430d000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f2c040f2000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2c03eec000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f2c03ce9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2c039e0000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2c03658000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2c03441000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2c052de000)
```

```
$ ls -1 /usr/lib/x86_64-linux-gnu/libboost_python*
/usr/lib/x86_64-linux-gnu/libboost_python.a
/usr/lib/x86_64-linux-gnu/libboost_python-py27.a
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.63.0
/usr/lib/x86_64-linux-gnu/libboost_python-py35.a
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so.1.63.0
/usr/lib/x86_64-linux-gnu/libboost_python.so
```

```
$ nm /usr/lib/x86_64-linux-gnu/libboost_python*.a | grep numpy | wc -l
0
```

Thanks in advance for any hints

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.