boost.numpy functions are throwing unresolved extern symbol link errors
Hello Boost-Community I have asked the following question everywhere
but nowhere has it been answered. I have now been advised to ask here.
I really hope there is someone on this mail list who can help me.
Unfortunately I don't have much time left and would be very grateful
for an answer.
With kind regards
Max
My Question:
I'm using normal Boost.NumPy functions in C++ like ndarray::get_data(),
and I get a "reference to unresolved external symbol" error. The .lib's
are linked and I have no approach on how to solve the error.
I am using Boost 1.74.
Here is a Code example:
#include
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/n...) 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 ? (See the exact command-line in the previous post). Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin...
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/n...) 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?
On 1/20/21 11:48 AM, Andrey Semashev wrote:
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/n...) 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).
Actually, no, it must be indirectly included in src/numpy/ndarray.cpp. But that file is a part of boost_numpy library, not boost_python. Does it get exported from boost_numpy?
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?
On 19. Jan 2021, at 13:52, Max Fetz via Boost
wrote: Hello Boost-Community I have asked the following question everywhere but nowhere has it been answered. I have now been advised to ask here.
I really hope there is someone on this mail list who can help me. Unfortunately I don't have much time left and would be very grateful for an answer.
Boost.Numpy is great if you are already using Boost as a dependency for your project and you don't want to add another dependency. If adding another dependency is an option, I would recommend to have a look at pybind11, which has a similar API and more features.
participants (4)
-
Andrey Semashev
-
Hans Dembinski
-
Max Fetz
-
Stefan Seefeld