1
I’m trying to develop a PHP extension with PHP-CPP on Windows. I was able to compile . a and . so of PHP-CPP with Mingw, however, when I compile the extension it does not find phpcpp. h.
My File Makefile:
NAME = Teste
INI_DIR = /etc/php5/conf.d
EXTENSION_DIR = $(shell php-config --extension-dir)
EXTENSION = ${NAME}.so
INI = ${NAME}.ini
COMPILER = g++
LINKER = g++
PHP_CONFIG = php-config
COMPILER_FLAGS = -Wall -c -O2 -std=c++11 -fpic -o
LINKER_FLAGS = -shared
LINKER_DEPENDENCIES = -lphpcpp
RM = rm -f
CP = cp -f
MKDIR = mkdir -p
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:%.cpp=%.o)
all: ${OBJECTS} ${EXTENSION}
${EXTENSION}: ${OBJECTS}
${LINKER} ${LINKER_FLAGS} -o $@ ${OBJECTS} ${LINKER_DEPENDENCIES}
${OBJECTS}:
${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp}
install:
${CP} ${EXTENSION} ${EXTENSION_DIR}
${CP} ${INI} ${INI_DIR}
clean:
${RM} ${EXTENSION} ${OBJECTS}
Folder structure:
main.cpp
Makefile
phpcpp. a
phpcpp.only
I added PHP-CPP files to Mingw’s Include folder and the error is now this:
C:\Users\PedroSoares\Desktop\PHP\build_folder>mingw32-make.exe all
g++ -Wall -c -O2 -std=c++11 -fpic -o main.o main.cpp
main.cpp:1:0: warning: -fpic ignored for target (all code is position independent) [enabled by default]
#include <phpcpp.h>
^
In file included from c:\mingw\include\phpcpp.h:34:0,
from main.cpp:1:
c:\mingw\include\phpcpp\inivalue.h:17:21: error: variable 'Php::PHPCPP_EXPORT Php::IniValue' has initializer but incomplete type
class PHPCPP_EXPORT IniValue
^
c:\mingw\include\phpcpp\inivalue.h:19:1: error: expected primary-expression before 'public'
public:
^
c:\mingw\include\phpcpp\inivalue.h:19:1: error: expected '}' before 'public'
c:\mingw\include\phpcpp\inivalue.h:19:1: error: expected ',' or ';' before 'public'
c:\mingw\include\phpcpp\inivalue.h:32:25: error: non-member function 'Php::operator int16_t()' cannot have cv-qualifier
operator int16_t () const
^
c:\mingw\include\phpcpp\inivalue.h:32:25: error: 'Php::operator int16_t()' must be a nonstatic member function
c:\mingw\include\phpcpp\inivalue.h:41:25: error: non-member function 'Php::operator int32_t()' cannot have cv-qualifier
operator int32_t () const
^
c:\mingw\include\phpcpp\inivalue.h:41:25: error: 'Php::operator int32_t()' must be a nonstatic member function
c:\mingw\include\phpcpp\inivalue.h:50:25: error: non-member function 'Php::operator int64_t()' cannot have cv-qualifier
operator int64_t () const
^
c:\mingw\include\phpcpp\inivalue.h:50:25: error: 'Php::operator int64_t()' must be a nonstatic member function
c:\mingw\include\phpcpp\inivalue.h:59:22: error: non-member function 'Php::operator bool()' cannot have cv-qualifier
operator bool () const
^
c:\mingw\include\phpcpp\inivalue.h:59:22: error: 'Php::operator bool()' must be a nonstatic member function
c:\mingw\include\phpcpp\inivalue.h:68:29: error: non-member function 'Php::operator std::string()' cannot have cv-qualifier
operator std::string () const
^
c:\mingw\include\phpcpp\inivalue.h:68:29: error: 'Php::operator std::string()' must be a nonstatic member function
c:\mingw\include\phpcpp\inivalue.h:77:30: error: non-member function 'Php::operator const char*()' cannot have cv-qualifier
operator const char * () const
^
c:\mingw\include\phpcpp\inivalue.h:77:30: error: 'Php::operator const char*()' must be a nonstatic member function
c:\mingw\include\phpcpp\inivalue.h:86:28: error: expected constructor, destructor, or type conversion before ';' token
operator double() const;
^
c:\mingw\include\phpcpp\inivalue.h:98:28: error: non-member function 'int64_t Php::numericValue()' cannot have cv-qualifier
int64_t numericValue() const;
^
c:\mingw\include\phpcpp\inivalue.h:104:22: error: non-member function 'bool Php::boolValue()' cannot have cv-qualifier
bool boolValue() const
^
c:\mingw\include\phpcpp\inivalue.h:113:31: error: non-member function 'std::string Php::stringValue()' cannot have cv-qualifier
std::string stringValue() const
^
c:\mingw\include\phpcpp\inivalue.h: In function 'std::string Php::stringValue()':
c:\mingw\include\phpcpp\inivalue.h:115:37: error: 'rawValue' was not declared in this scope
return std::string(rawValue());
^
c:\mingw\include\phpcpp\inivalue.h: At global scope:
c:\mingw\include\phpcpp\inivalue.h:122:28: error: non-member function 'const char* Php::rawValue()' cannot have cv-qualifier
const char *rawValue() const;
^
c:\mingw\include\phpcpp\inivalue.h:125:1: error: expected unqualified-id before 'private'
private:
^
c:\mingw\include\phpcpp\inivalue.h:147:1: error: 'PHPCPP_EXPORT' does not name a type
PHPCPP_EXPORT std::ostream &operator<<(std::ostream &stream, const IniValue &ini_val);
^
c:\mingw\include\phpcpp\inivalue.h:153:1: error: expected declaration before '}' token
}
^
Makefile:21: recipe for target 'main.o' failed
mingw32-make.exe: *** [main.o] Error 1
How you are running the build command?
– Guilherme Nascimento
set PATH=%PATH%;C: Mingw bin; mingw32-make.exe
– Pedro Soares
A Peter thing
/etc/php5/conf.d
is a linux and not windows way. You have to compile php-cpp and play . lib generated in the mingw folder (I can’t remember which folder, I think it was the /libs) and have to put the files. h from php-cpp (not from your project) in a folder that I don’t remember (sorry it’s been over a year since I used mingw :/)– Guilherme Nascimento
the /etc/php5/conf. d line is only for installation, the problem is when compiling. I already added the extensions to the /lib folder, but I couldn’t find the other folder to put php-cpp source. Only with the files in the /lib folder makes no difference, the error persists.
– Pedro Soares
Extensions you refer to
.lib
? In case I say that in libs/ folder there has to be a file calledphpcpp.lib
(I think it’s something like that), and there’s another folder (which I don’t remember the name) that has to be thephpcpp.h
. I will try to install Mingw and compile phpcpp (install) and then try to create an extension.– Guilherme Nascimento
the extension na is . lib, . o and .so. If you want I can post my PHP-CPP Makefile, because I have to modify many things to compile on Windows.
– Pedro Soares
I don’t understand well, but I think you really don’t understand what I said, I’m not talking about the extension you’re creating but how to install the
phpcpp
along with mingw, what I mean is that you should compile the "installer" of phpcpp by mingw, so it will generate a file calledphpcpp.lib
, that file should go in the mingw folder along with the filephpcpp.h
(each one in its respective folder) then ae yes you should try to compile the "its extension". What I mean, if it accuses that phpcpp is missing. h is because it is not in the mingw folder.– Guilherme Nascimento
I did what I said, now comes the mistake that’s up there.
– Pedro Soares
By error it seems that you forget some other file that comes with CPP. Have you downloaded PHPCPP compatible with which compiler? Or it is cross-Compiler?
– Guilherme Nascimento
He is cross-pilot.
– Pedro Soares
I’ll do this, it may take a few days, but I’ll install Mingw and try to compile phpcpp. As soon as I get a feedback.
– Guilherme Nascimento
OK, thank you very much.
– Pedro Soares