phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
http://pecl.php.net/package/v8js
MIT License
1.83k stars 200 forks source link

Cannot Make File for PHP 7.1 on Ubuntu 14.04 #354

Closed sltwtr-admin closed 6 years ago

sltwtr-admin commented 6 years ago

I followed this tutorial to install V8 and then build the V8js .so file. https://github.com/phpv8/v8js/blob/php7/README.Linux.md

But I get an error, any ideas? To me it seems I'm compiling for PHP7.1 with PHP5. But I set the CLI to use 7.1. I don't know.

root@ubuntu:/tmp/v8js# make /bin/bash /tmp/v8js/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/opt/v8/include -I/opt/v8 -DHAVE_CONFIG_H -g -O2 -c /tmp/v8js/v8js_array_access.cc -o v8js_array_access.lo libtool: compile: g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/opt/v8/include -I/opt/v8 -DHAVE_CONFIG_H -g -O2 -c /tmp/v8js/v8js_array_access.cc -fPIC -DPIC -o .libs/v8js_array_access.o /tmp/v8js/v8js_array_access.cc:42:45: error: macro "ZVAL_STRING" requires 3 arguments, but only 2 given ZVAL_STRING(&fci.function_name, method_name); ^ In file included from /tmp/v8js/php_v8js_macros.h:54:0, from /tmp/v8js/v8js_array_access.cc:17: /tmp/v8js/v8js_class.h:61:18: error: ISO C++ forbids declaration of 'type name' with no type [-fpermissive] std::map<const zend_string ,v8js_function_tmpl_t> template_cache; ^ /tmp/v8js/v8js_class.h:61:52: error: wrong number of template arguments (1, should be 4) std::map<const zend_string ,v8js_function_tmpl_t> template_cache; ^ In file included from /usr/include/c++/4.8/map:61:0, from /tmp/v8js/php_v8js_macros.h:26, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/c++/4.8/bits/stl_map.h:96:11: error: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map' class map ^ In file included from /tmp/v8js/v8js_array_access.cc:17:0: /tmp/v8js/php_v8js_macros.h:88:40: error: 'zend_long' was not declared in this scope v8::Local zend_long_to_v8js(zend_long, v8::Isolate ); ^ /tmp/v8js/php_v8js_macros.h:88:63: error: expected primary-expression before '' token v8::Local zend_long_to_v8js(zend_long, v8::Isolate ); ^ /tmp/v8js/php_v8js_macros.h:88:64: error: expected primary-expression before ')' token v8::Local zend_long_to_v8js(zend_long, v8::Isolate ); ^ /tmp/v8js/php_v8js_macros.h:95:2: error: 'zend_string' does not name a type zend_string variable_name; ^ /tmp/v8js/v8js_array_access.cc: In function 'zval v8js_array_access_dispatch(zend_object, const char*, int, uint32_t, zval)': /tmp/v8js/v8js_array_access.cc:42:2: error: 'ZVAL_STRING' was not declared in this scope ZVAL_STRING(&fci.function_name, method_name); ^ /tmp/v8js/v8js_array_access.cc:43:6: error: 'zend_fcall_info' has no member named 'retval' fci.retval = &php_value; ^ /tmp/v8js/v8js_array_access.cc:50:13: error: cannot convert 'zval [2] {aka _zval_struct [2]}' to 'zval {aka _zval_struct}' in assignment fci.params = params; ^ /tmp/v8js/v8js_array_access.cc:52:6: error: 'zend_fcall_info' has no member named 'object' fci.object = object; ^ In file included from /usr/include/php5/Zend/zend.h:841:0, from /usr/include/php5/main/php.h:35, from /tmp/v8js/php_v8js_macros.h:42, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/php5/Zend/zend_variables.h:56:64: error: cannot convert 'zval {aka _zval_struct}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_dtor(zval*)'

define zval_dtor(zvalue) _zval_dtor((zvalue) ZEND_FILE_LINE_CC)

                                                            ^

/tmp/v8js/v8js_array_access.cc:56:2: note: in expansion of macro 'zval_dtor' zval_dtor(&fci.function_name); ^ /tmp/v8js/v8js_array_access.cc: In function 'void v8js_array_access_getter(uint32_t, const v8::PropertyCallbackInfo&)': /tmp/v8js/v8js_array_access.cc:71:20: error: 'ZVAL_UNDEF' was not declared in this scope ZVAL_UNDEF(&zvalue); ^ In file included from /usr/include/php5/Zend/zend.h:841:0, from /usr/include/php5/main/php.h:35, from /tmp/v8js/php_v8js_macros.h:42, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/php5/Zend/zend_variables.h:57:76: error: cannot convert 'zval {aka _zval_struct}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_ptr_dtor(zval**)'

define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)

                                                                        ^

/tmp/v8js/v8js_array_access.cc:75:2: note: in expansion of macro 'zval_ptr_dtor' zval_ptr_dtor(&php_value); ^ /tmp/v8js/v8js_array_access.cc: In function 'void v8js_array_access_setter(uint32_t, v8::Local, const v8::PropertyCallbackInfo&)': /tmp/v8js/v8js_array_access.cc:90:20: error: 'ZVAL_UNDEF' was not declared in this scope ZVAL_UNDEF(&zvalue); ^ In file included from /usr/include/php5/Zend/zend.h:841:0, from /usr/include/php5/main/php.h:35, from /tmp/v8js/php_v8js_macros.h:42, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/php5/Zend/zend_variables.h:57:76: error: cannot convert 'zval {aka _zval_struct}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_ptr_dtor(zval**)'

define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)

                                                                        ^

/tmp/v8js/v8js_array_access.cc:98:2: note: in expansion of macro 'zval_ptr_dtor' zval_ptr_dtor(&php_value); ^ /usr/include/php5/Zend/zend_variables.h:57:76: error: cannot convert 'zval {aka _zval_struct}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_ptr_dtor(zval**)'

define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)

                                                                        ^

/tmp/v8js/v8js_array_access.cc:106:2: note: in expansion of macro 'zval_ptr_dtor' zval_ptr_dtor(&zvalue); ^ /tmp/v8js/v8js_array_access.cc: In function 'int v8js_array_access_get_count_result(zend_object)': /tmp/v8js/v8js_array_access.cc:114:20: error: 'ZVAL_UNDEF' was not declared in this scope ZVAL_UNDEF(&zvalue); ^ In file included from /usr/include/php5/Zend/zend.h:841:0, from /usr/include/php5/main/php.h:35, from /tmp/v8js/php_v8js_macros.h:42, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/php5/Zend/zend_variables.h:57:76: error: cannot convert 'zval {aka _zval_struct*}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_ptr_dtor(zval**)'

define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)

                                                                        ^

/tmp/v8js/v8js_array_access.cc:120:3: note: in expansion of macro 'zval_ptr_dtor' zval_ptr_dtor(&php_value); ^ /tmp/v8js/v8js_array_access.cc:124:2: error: 'zend_long' was not declared in this scope zend_long result = Z_LVAL(php_value); ^ /tmp/v8js/v8js_array_access.cc:124:12: error: expected ';' before 'result' zend_long result = Z_LVAL(php_value); ^ /tmp/v8js/v8js_array_access.cc:126:6: error: 'result' was not declared in this scope if (result > std::numeric_limits::max()) { ^ /tmp/v8js/v8js_array_access.cc:132:26: error: 'result' was not declared in this scope return static_cast(result); ^ /tmp/v8js/v8js_array_access.cc: In function 'bool v8js_array_access_isset_p(zend_object, int)': /tmp/v8js/v8js_array_access.cc:139:20: error: 'ZVAL_UNDEF' was not declared in this scope ZVAL_UNDEF(&zvalue); ^ /tmp/v8js/v8js_array_access.cc:143:26: error: 'IS_TRUE' was not declared in this scope if(Z_TYPE(php_value) != IS_TRUE && Z_TYPE(php_value) != IS_FALSE) { ^ /tmp/v8js/v8js_array_access.cc:143:58: error: 'IS_FALSE' was not declared in this scope if(Z_TYPE(php_value) != IS_TRUE && Z_TYPE(php_value) != IS_FALSE) { ^ In file included from /usr/include/php5/Zend/zend.h:841:0, from /usr/include/php5/main/php.h:35, from /tmp/v8js/php_v8js_macros.h:42, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/php5/Zend/zend_variables.h:57:76: error: cannot convert 'zval {aka _zval_struct*}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_ptr_dtor(zval**)'

define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)

                                                                        ^

/tmp/v8js/v8js_array_access.cc:145:3: note: in expansion of macro 'zval_ptr_dtor' zval_ptr_dtor(&php_value); ^ /tmp/v8js/v8js_array_access.cc:149:30: error: 'IS_TRUE' was not declared in this scope return Z_TYPE(php_value) == IS_TRUE; ^ /tmp/v8js/v8js_array_access.cc: In function 'void v8js_array_access_deleter(uint32_t, const v8::PropertyCallbackInfo&)': /tmp/v8js/v8js_array_access.cc:174:20: error: 'ZVAL_UNDEF' was not declared in this scope ZVAL_UNDEF(&zvalue); ^ In file included from /usr/include/php5/Zend/zend.h:841:0, from /usr/include/php5/main/php.h:35, from /tmp/v8js/php_v8js_macros.h:42, from /tmp/v8js/v8js_array_access.cc:17: /usr/include/php5/Zend/zend_variables.h:57:76: error: cannot convert 'zval {aka _zval_struct}' to 'zval {aka _zval_struct}' for argument '1' to 'void _zval_ptr_dtor(zval**)'

define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)

                                                                        ^

/tmp/v8js/v8js_array_access.cc:177:2: note: in expansion of macro 'zval_ptr_dtor' zval_ptr_dtor(&php_value); ^ make: *** [v8js_array_access.lo] Error 1

stesie commented 6 years ago

I'm confused, which PHP version do you want to compile for? PHP 5 or 7.1?

Your installed PHP version seems to be PHP5 ... yet the question is, do you want to build against that or do you have multiple PHP versions around and actually want to build against a different one? (In that case make sure to call the correct phpize and ./configure --with-php-config=/path/to/php/7.1/php-config)

In case you really want to compile this extension on PHP 5 make sure to check out the branch named master and build from there. But keep in mind that that one's a bit dated, might very well not work with most recent V8 versions...

sltwtr-admin commented 6 years ago

I want to compile for 7.1. After Googling the error message I belive it indicates there is a PHP mismatch somewhere.

My server is a standard Serverpilot Ubuntu 14.04 setup where I can choose PHP versions from 5.5 up to 7.2. Initially I tried to solve the error by switching my PHP CLI version to 7.1, the same as Apache, by running this command sudo dpkg-reconfigure sp-php-cli. The command line now shows it is using 7.1, but it didn't solve the make errors.

I will try to call the correct phpize and ./configure --with-php-config=/path/to/php/7.1/php-config.

Thanks for your insights into this issue @stesie. I am open ears to anything else you can think of.

sltwtr-admin commented 6 years ago

I believe the phpize is the correct version because there is phpize and phpize5 in /usr/bin

screen shot 2018-03-07 at 9 51 10 am

After running .configure, I see the following output but calling make thereafter results in the same error as my original post.

root@ubuntu:/tmp/v8js# ./configure --with-php-config=/usr/bin/php-config --with-v8js=/opt/v8 LDFLAGS="-lstdc++"
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib/php5/20121212
checking for PHP installed headers prefix... /usr/include/php5
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for V8 Javascript Engine... yes, shared
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for C standard version... c++11
checking how to allow c++11 narrowing... 
checking for libv8_libplatform... found
checking for V8 version... 6.4.388.18
checking for natives_blob.bin... found (/opt/v8/lib/natives_blob.bin)
checking for snapshot_blob.bin... found (/opt/v8/lib/snapshot_blob.bin)
checking for v8::ArrayBuffer::Allocator::NewDefaultAllocator... yes
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
stesie commented 6 years ago

each of your php installations should have it's own phpize and php-config utility, ... usually they are located right next to the php binary. So like /opt/sp/php7.1/bin/phpize et al

checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib checking for PHP extension directory... /usr/lib/php5/20121212 checking for PHP installed headers prefix... /usr/include/php5

... here it shows that it definitely picked the wrong headers (i.e. wrong php-config tool). I'd suppose that the correct headers are under /opt/sp/php7.1/include ...

sltwtr-admin commented 6 years ago

Who's the man?!! @stesie Your answer nailed it. No errors after pointing to the correct phpize and the correct PHP config.

To summarize:

/opt/sp/php7.1/bin/phpize ./configure --with-php-config=/opt/sp/php7.1/bin/php-config --with-v8js=/opt/v8 LDFLAGS="-lstdc++"

Thanks a million all of your help!