I'm trying to create a PHP extension for Windows, using the Visual Studio Express. I started the extension from scratch and had just test.cpp
file, where I wrote some code. Although the code compiled and worked well, during compilation it produced several warnings, I'd rather get rid of.
I reduced the file to a single line, which reproduces those warnings:
#include "php.h"
Building such an empty DLL I get:
>Compiling...
>test.cpp
>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(620) : warning C4273: 'getwchar' : inconsistent dll linkage
> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(435) : see previous definition of 'getwchar'
>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(622) : warning C4273: 'putwchar' : inconsistent dll linkage
> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(437) : see previous definition of 'putwchar'
What is the proper way to fix these two warnings?
I've tried to investigate the issue, and checked if I forgot some preprocessor directive. But I couldn't find anything applicable to influence that stdio.h
properly.
Here is the list of my preprocessor directives, as set up in the project configuration:
WIN32
NDEBUG
_WINDOWS
_USRDLL
TEST_EXPORTS
PHP_WIN32
ZEND_WIN32
ZTS=1
ZEND_DEBUG=0
Inherited values:
_WINDLL
_UNICODE
UNICODE
It looks pretty same as other PHP projects have. I've also studied the stdio.h
, but haven't found appropriate preprocessor directives to set.
So, the main question is divided into smaller questions:
getwchar()
and putwchar()
functions imported or declared inline? stdio.h
tries to do that simultaneously.Eventually I managed to find the issue - that was the .cpp extension, which caused the file to be compiled as C++, while the PHP is written in plain C.
The simplest solution is just to rename file to have .c extension. And, of course, write the source in C.