Skip to content

Pybind11 no longer compiles with GCC 7.2 and Python 2.7 #1804

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

Closed
MichaelGoulding opened this issue Jun 12, 2019 · 7 comments
Closed

Pybind11 no longer compiles with GCC 7.2 and Python 2.7 #1804

MichaelGoulding opened this issue Jun 12, 2019 · 7 comments

Comments

@MichaelGoulding
Copy link
Contributor

MichaelGoulding commented Jun 12, 2019

Pybind11 no longer compiles with GCC and Python 2.7

I get the following errors when compiling with v2.3.0:

In file included from /home/thedude/Anaconda43/include/python2.7/Python.h:8:0,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/detail/common.h:112,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/pytypes.h:12,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/cast.h:13,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/attr.h:13,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/pybind11.h:49,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../shared/PythonDef.h:17,
                 from /mnt/_work/10/s/code/Binaries/exe/stdafx.h:6,
                 from /mnt/_work/10/s/code/Binaries/exe/src/exe.cpp:6:
/home/thedude/Anaconda43/include/python2.7/pyconfig.h:1190:0: error: "_POSIX_C_SOURCE" redefined [-Werror]
 #define _POSIX_C_SOURCE 200112L
 
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cxxabi.h:49,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/pybind11.h:45,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../shared/PythonDef.h:17,
                 from /mnt/_work/10/s/code/Binaries/exe/stdafx.h:6,
                 from /mnt/_work/10/s/code/Binaries/exe/src/exe.cpp:6:
/usr/include/features.h:265:0: note: this is the location of the previous definition
 # define _POSIX_C_SOURCE 200809L
 
In file included from /home/thedude/Anaconda43/include/python2.7/Python.h:8:0,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/detail/common.h:112,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/pytypes.h:12,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/cast.h:13,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/attr.h:13,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/pybind11.h:49,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../shared/PythonDef.h:17,
                 from /mnt/_work/10/s/code/Binaries/exe/stdafx.h:6,
                 from /mnt/_work/10/s/code/Binaries/exe/src/exe.cpp:6:
/home/thedude/Anaconda43/include/python2.7/pyconfig.h:1212:0: error: "_XOPEN_SOURCE" redefined [-Werror]
 #define _XOPEN_SOURCE 600
 
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cxxabi.h:49,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../thirdparty/pybind11/include/pybind11/pybind11.h:45,
                 from /mnt/_work/10/s/code/Binaries/exe/../../../shared/PythonDef.h:17,
                 from /mnt/_work/10/s/code/Binaries/exe/stdafx.h:6,
                 from /mnt/_work/10/s/code/Binaries/exe/src/exe.cpp:6:
/usr/include/features.h:202:0: note: this is the location of the previous definition
 # define _XOPEN_SOURCE 700

I believe this is introduced by commit: 69dc380

@wjakob
Copy link
Member

wjakob commented Jun 12, 2019

Hi Michael,

our travis CI suite tests GCC on Linux, with Python 2.7, which at least seems to pass the test suite:

https://travis-ci.org/pybind/pybind11/jobs/544890337

Can you clarify on how your setup is different?

Best,
Wenzel

@wjakob
Copy link
Member

wjakob commented Jun 12, 2019

btw, these are actually warnings that get turned into errors due to your addition of a -Werror flag.

@wjakob
Copy link
Member

wjakob commented Jun 12, 2019

One option might be to simply include that header a few lines before. Does the following patch fix things?

diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h
index f1d91c7..0cc5dd5 100644
--- a/include/pybind11/pybind11.h
+++ b/include/pybind11/pybind11.h
@@ -41,16 +41,15 @@
 #  endif
 #endif
 
-#if defined(__GNUG__) && !defined(__clang__)
- #include <cxxabi.h>
-#endif
-
-
 #include "attr.h"
 #include "options.h"
 #include "detail/class.h"
 #include "detail/init.h"
 
+#if defined(__GNUG__) && !defined(__clang__)
+#  include <cxxabi.h>
+#endif
+
 NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
 
 /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object

@MichaelGoulding
Copy link
Contributor Author

We are using GCC version 7.2. Perhaps that is the difference.

@MichaelGoulding MichaelGoulding changed the title Pybind11 no longer compiles with GCC and Python 2.7 Pybind11 no longer compiles with GCC 7.2 and Python 2.7 Jun 12, 2019
@MichaelGoulding
Copy link
Contributor Author

Yes, that patch fixes things.

@wjakob
Copy link
Member

wjakob commented Jun 19, 2019

Merged, will be part of v2.3.1

@henryiii
Copy link
Collaborator

Updated to 2.3.0 and this killed my tests (with -Werror on). Glad to see it's fixed. Thanks!

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