Skip to content

Commit bd7b8ec

Browse files
SPKorhonenstefanseefeld
authored andcommitted
Fix for missing export symbols, issue boostorg#98 (boostorg#110)
Fix for missing export symbols in shared library of boost::python::numpy
1 parent 0224f54 commit bd7b8ec

File tree

7 files changed

+95
-6
lines changed

7 files changed

+95
-6
lines changed

build/Jamfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ rule lib_boost_numpy ( is-py3 ? )
137137
numpy/scalars.cpp
138138
numpy/ufunc.cpp
139139
: # requirements
140+
<link>static:<define>BOOST_NUMPY_STATIC_LIB
141+
<define>BOOST_NUMPY_SOURCE
140142
[ cond [ python.numpy ] : <library>/python//python_for_extensions ]
141143
[ unless [ python.numpy ] : <build>no ]
142144
<include>$(numpy-include)
@@ -150,6 +152,7 @@ rule lib_boost_numpy ( is-py3 ? )
150152
: # default build
151153
<link>shared
152154
: # usage requirements
155+
<link>static:<define>BOOST_NUMPY_STATIC_LIB
153156
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
154157
;
155158
}

include/boost/python/numpy.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/python/numpy/matrix.hpp>
1414
#include <boost/python/numpy/ufunc.hpp>
1515
#include <boost/python/numpy/invoke_matching.hpp>
16+
#include <boost/python/numpy/config.hpp>
1617

1718
namespace boost { namespace python { namespace numpy {
1819

@@ -26,7 +27,7 @@ namespace boost { namespace python { namespace numpy {
2627
* and "import_ufunc()", and then calls
2728
* dtype::register_scalar_converters().
2829
*/
29-
void initialize(bool register_scalar_converters=true);
30+
BOOST_NUMPY_DECL void initialize(bool register_scalar_converters=true);
3031

3132
}}} // namespace boost::python::numpy
3233

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// (C) Copyright Samuli-Petrus Korhonen 2017.
2+
// Distributed under the Boost Software License, Version 1.0. (See
3+
// accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
//
6+
// The author gratefully acknowleges the support of NMR Solutions, Inc., in
7+
// producing this work.
8+
9+
// Revision History:
10+
// 15 Feb 17 Initial version
11+
12+
#ifndef CONFIG_NUMPY20170215_H_
13+
# define CONFIG_NUMPY20170215_H_
14+
15+
# include <boost/config.hpp>
16+
17+
/*****************************************************************************
18+
*
19+
* Set up dll import/export options:
20+
*
21+
****************************************************************************/
22+
23+
// backwards compatibility:
24+
#ifdef BOOST_NUMPY_STATIC_LIB
25+
# define BOOST_NUMPY_STATIC_LINK
26+
# elif !defined(BOOST_NUMPY_DYNAMIC_LIB)
27+
# define BOOST_NUMPY_DYNAMIC_LIB
28+
#endif
29+
30+
#if defined(BOOST_NUMPY_DYNAMIC_LIB)
31+
# if defined(BOOST_SYMBOL_EXPORT)
32+
# if defined(BOOST_NUMPY_SOURCE)
33+
# define BOOST_NUMPY_DECL BOOST_SYMBOL_EXPORT
34+
# define BOOST_NUMPY_DECL_FORWARD BOOST_SYMBOL_FORWARD_EXPORT
35+
# define BOOST_NUMPY_DECL_EXCEPTION BOOST_EXCEPTION_EXPORT
36+
# define BOOST_NUMPY_BUILD_DLL
37+
# else
38+
# define BOOST_NUMPY_DECL BOOST_SYMBOL_IMPORT
39+
# define BOOST_NUMPY_DECL_FORWARD BOOST_SYMBOL_FORWARD_IMPORT
40+
# define BOOST_NUMPY_DECL_EXCEPTION BOOST_EXCEPTION_IMPORT
41+
# endif
42+
# endif
43+
44+
#endif
45+
46+
#ifndef BOOST_NUMPY_DECL
47+
# define BOOST_NUMPY_DECL
48+
#endif
49+
50+
#ifndef BOOST_NUMPY_DECL_FORWARD
51+
# define BOOST_NUMPY_DECL_FORWARD
52+
#endif
53+
54+
#ifndef BOOST_NUMPY_DECL_EXCEPTION
55+
# define BOOST_NUMPY_DECL_EXCEPTION
56+
#endif
57+
58+
// enable automatic library variant selection ------------------------------//
59+
60+
#if !defined(BOOST_NUMPY_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_NUMPY_NO_LIB)
61+
//
62+
// Set the name of our library, this will get undef'ed by auto_link.hpp
63+
// once it's done with it:
64+
//
65+
#define BOOST_LIB_NAME boost_numpy
66+
//
67+
// If we're importing code from a dll, then tell auto_link.hpp about it:
68+
//
69+
#ifdef BOOST_NUMPY_DYNAMIC_LIB
70+
# define BOOST_DYN_LINK
71+
#endif
72+
//
73+
// And include the header that does the work:
74+
//
75+
#include <boost/config/auto_link.hpp>
76+
#endif // auto-linking disabled
77+
78+
#endif // CONFIG_NUMPY20170215_H_

include/boost/python/numpy/dtype.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <boost/python.hpp>
1616
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
17+
#include <boost/python/numpy/config.hpp>
1718

1819
#include <boost/mpl/for_each.hpp>
1920
#include <boost/type_traits/add_pointer.hpp>
@@ -25,7 +26,7 @@ namespace boost { namespace python { namespace numpy {
2526
*
2627
* @todo This could have a lot more interesting accessors.
2728
*/
28-
class dtype : public object {
29+
class BOOST_NUMPY_DECL dtype : public object {
2930
static python::detail::new_reference convert(object::object_cref arg, bool align);
3031
public:
3132

include/boost/python/numpy/matrix.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <boost/python.hpp>
1515
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
1616
#include <boost/python/numpy/ndarray.hpp>
17+
#include <boost/python/numpy/config.hpp>
18+
1719

1820
namespace boost { namespace python { namespace numpy {
1921

@@ -27,7 +29,7 @@ namespace boost { namespace python { namespace numpy {
2729
* bad things happen when Python shuts down. I think this solution is safe, but I'd
2830
* love to get that confirmed.
2931
*/
30-
class matrix : public ndarray
32+
class BOOST_NUMPY_DECL matrix : public ndarray
3133
{
3234
static object construct(object_cref obj, dtype const & dt, bool copy);
3335
static object construct(object_cref obj, bool copy);
@@ -59,7 +61,7 @@ class matrix : public ndarray
5961
* return a numpy.matrix instead.
6062
*/
6163
template <typename Base = default_call_policies>
62-
struct as_matrix : Base
64+
struct BOOST_NUMPY_DECL as_matrix : Base
6365
{
6466
static PyObject * postcall(PyObject *, PyObject * result)
6567
{

include/boost/python/numpy/ndarray.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <boost/type_traits/is_integral.hpp>
1717
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
1818
#include <boost/python/numpy/dtype.hpp>
19+
#include <boost/python/numpy/config.hpp>
20+
1921
#include <vector>
2022

2123
namespace boost { namespace python { namespace numpy {
@@ -26,7 +28,8 @@ namespace boost { namespace python { namespace numpy {
2628
* @todo This could have a lot more functionality (like boost::python::numeric::array).
2729
* Right now all that exists is what was needed to move raw data between C++ and Python.
2830
*/
29-
class ndarray : public object
31+
32+
class BOOST_NUMPY_DECL ndarray : public object
3033
{
3134

3235
/**

include/boost/python/numpy/ufunc.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
1616
#include <boost/python/numpy/dtype.hpp>
1717
#include <boost/python/numpy/ndarray.hpp>
18+
#include <boost/python/numpy/config.hpp>
1819

1920
namespace boost { namespace python { namespace numpy {
2021

@@ -34,7 +35,7 @@ namespace boost { namespace python { namespace numpy {
3435
* It's more dangerous than most object managers, however - maybe it actually belongs in
3536
* a detail namespace?
3637
*/
37-
class multi_iter : public object
38+
class BOOST_NUMPY_DECL multi_iter : public object
3839
{
3940
public:
4041

0 commit comments

Comments
 (0)