Bug #66009 [Asn->Csd]: Failed compilation of PHP extension with C++ std library using VS 2012
| From: | ab@php.net | Date: | Sat, 04 Jan 2014 00:42:29 +0000 |
| Subject: | Bug #66009 [Asn->Csd]: Failed compilation of PHP extension with C++ std library using VS 2012 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183579@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66009&edit=1
ID: 66009
Updated by: ab@php.net
Reported by: pvasilevich at parallels dot com
Summary: Failed compilation of PHP extension with C++ std
library using VS 2012
-Status: Assigned
+Status: Closed
Type: Bug
Package: Compile Failure
Operating System: Windows
PHP Version: 5.5.5
Assigned To: ab
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae1cc83f98b779eb3f01779d416bde994332efd3
Log: Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
Previous Comments:
------------------------------------------------------------------------
[2013-10-31 10:17:20] pvasilevich at parallels dot com
Description:
------------
Suppose you have an PHP extension that uses C++ standard library.
one of source files looks like:
#ifdef __cplusplus
extern "C" {
#endif
#include "php.h"
#ifdef __cplusplus
}
#endif
#include <string>
...
After trying to compile this extension using Visual Studio 2012 you got the following error:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xkeycheck.h(242): fatal error C1189:
#error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the
forbidden macro.
Documentation for Visual Studio says:
http://msdn.microsoft.com/en-us/libraRy/bb531344%28v=vs.110%29.aspx
C++11 17.6.4.3.1 [macro.names]/2 forbids macro-izing keywords when C++ Standard Library headers are
included. The headers now emit compiler errors if they detect macro-ized keywords. (Defining
_ALLOW_KEYWORD_MACROS allows such code to compile, but we strongly discourage that usage.)
This problem appeared because of the following code in PHP:
\TSRM\tsrm_config.w32.h
\Zend\zend_config.w32.h
#undef inline
#ifdef ZEND_WIN32_FORCE_INLINE
# define inline __forceinline
#else
# define inline
#endif
Redefinition of keywords is forbidden in C++11 standard.
Possible workaround is to use keyword provided by Microsoft:
#define _ALLOW_KEYWORD_MACROS
But this is not enough because in this case macro inline will be defined as empty, bringing problems
in other code compilation (those functions that were defined as inline are not inline anymore), for
example:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\ostream(1020): error C2491:
'std::endl' : definition of dllimport function not allowed
Possible workaround for now is to define both:
#define _ALLOW_KEYWORD_MACROS
#define ZEND_WIN32_FORCE_INLINE
Could you please resolve this issue somehow, for example by changing your define as follows:
#ifdef ZEND_WIN32_FORCE_INLINE
# undef inline
# define inline __forceinline
#endif
or wrap it using other #ifdef to be able to stop redefining of inline macro in PHP code.
Test script:
---------------
#ifdef __cplusplus
extern "C" {
#endif
#include "php.h"
#ifdef __cplusplus
}
#endif
#include <string>
...
Expected result:
----------------
There is no redefinition of standard keyword "inline" in PHP code.
Actual result:
--------------
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xkeycheck.h(242): fatal error C1189:
#error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the
forbidden macro.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66009&edit=1