Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including Boost Python libraries produces C2039 compiler error #130

Open
zerovirus123 opened this issue Nov 23, 2022 · 7 comments
Open

Including Boost Python libraries produces C2039 compiler error #130

zerovirus123 opened this issue Nov 23, 2022 · 7 comments

Comments

@zerovirus123
Copy link

I have built Boost_1.76 with the following configurations.

Compiler: MSVC 143
Build Tools: bootstrap.bat, b2 engine
Python Version: 3.7
b2 Command: b2 --build-dir=build/x64 address-model=64 threading=multi --build-type=complete --stagedir=./stage/x64 -j 12
// Conversion.hpp
#include <boost/python.hpp>        // import produces C2039
#include <boost/python/numpy.hpp>  // import produces C2039
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
// Conversion.cpp
#include "Conversion.hpp" // importing the header file produces the compiler error

I am compiling the project with the following specs.

Compiler: MSVC cl.exe
C++ Standard: ISO C++17
Platform Toolset: Visual Studio 2022 (v143)

The compilation generates the following error.

C2039: '_copysign' is not a member of 'std' 
File: boost_1_76_python37\boost\core\cmath.hpp

I looked at python.hpp and numpy.hpp and could only find a reference to std::cmath inside boost\python\detail\wrap_python.py, which is used over boost::core::cmath. I checked the std::cmath header and copysign is neither declared nor defined. How do I make sure that my Boost library uses the copysign in boost::core::cmath?

@Lastique
Copy link
Member

Looks like copysign is defined as a macro somewhere, possibly in the Python headers. If that's the case, Python should be fixed, IMHO.

@Lastique
Copy link
Member

It might also be useful to add a workaround to Boost.Python. CC @stefanseefeld.

@pdimov
Copy link
Member

pdimov commented Nov 23, 2022

Check whether your pyconfig.h file contains #define copysign _copysign. I can't find such a line in my Python 3.9 installation, only a comment in pymath.h about it, but it might have been present in 3.7.

@zerovirus123
Copy link
Author

@pdimov Hi Peter, I checked pyconfig.h and the directive is present in Python37.

@pdimov
Copy link
Member

pdimov commented Nov 24, 2022

The easiest fix then is to upgrade to a more recent Python version, one that no longer has the #define. I'm not sure what we can do on the Boost side to defend against that.

@zerovirus123
Copy link
Author

@pdimov Python310 has the #define HAVE_COPYSIGN 1 directive. Does that mean that copysign is still defined in the later Python versions.

If I build my Boost library with Python310, then the compiler would not produce the _copysign namespace error.

@pdimov
Copy link
Member

pdimov commented Nov 25, 2022

#define HAVE_COPYSIGN 1 in pyconfig.h just means that the compiler has a copysign function, which Python can use without needing to redefine copysign to _copysign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants