Bug #66009 [NEW]: Failed compilation of PHP extension with C++ std library using VS 2012
| From: | pvasilevich at parallels dot com | Date: | Thu, 31 Oct 2013 10:17:21 +0000 |
| Subject: | Bug #66009 [NEW]: Failed compilation of PHP extension with C++ std library using VS 2012 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-182514@lists.php.net to get a copy of this message | ||
From: pvasilevich at parallels dot com
Operating system: Windows
PHP version: 5.5.5
Package: Compile Failure
Bug Type: Bug
Bug description:Failed compilation of PHP extension with C++ std library using VS 2012
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 bug report at https://bugs.php.net/bug.php?id=66009&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66009&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66009&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66009&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66009&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66009&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66009&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66009&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66009&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66009&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66009&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66009&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66009&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66009&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66009&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66009&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66009&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66009&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66009&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66009&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66009&r=mysqlcfg