Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2021-01-20 08:48:07


On 1/20/21 6:23 AM, Stefan Seefeld via Boost wrote:
> Hello,
>
> I'm unfortunately not familiar enough with the platform (Windows) or
> this compiler (MSVC) to help, but I would like to add some notes in case
> someone else on this list has ideas:
>
> Compiling a trivial C++ applet based on code such as
> https://boostorg.github.io/python/doc/html/numpy/tutorial/ndarray.html
> on Linux simply requires a command such as
>
> ```
>
> g++ -I /usr/include/python3.8 -o np_test np_test.cpp -lboost_numpy38
> -lboost_python38 -lpython3.8
> ```
>
> I find particularly confusing that the MSVC linker would generate a
> missing symbol error for the `ndarray::get_data()` function, given that
> this function (as defined in
> https://github.com/boostorg/python/blob/develop/include/boost/python/numpy/ndarray.hpp#L101)
> ought to be inlined, and not generate a symbol at all.
>
> Does anyone familiar with this platform have an idea under what
> circumstances this may result in a link error ?

The class is marked with BOOST_NUMPY_DECL, which, I assume, is
__declspec(dllexport)/(dllimport) on Windows. This means that when
compiling the user's code the compiler may look for the imported
function from the dll when inlining does not happen, which is usual in
debug builds, for example.

The fact that there is no such function probably means that the class is
never included when Boost.Python is compiled (i.e. when the class is
marked as dllexport).

Marking the whole class as dllexport/dllimport has other consequences,
such as exporting type information for the class. If this is not needed,
I would suggest marking individual members to export/import and not the
whole class.

> (See the exact
> command-line in the previous post).

What previous post?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk