Closed WalkerPnD closed 6 years ago
Hi @walker-walks, in order to get this compiled, you need to have php
installed as a library.
To do this on MacOS, you need to get Homebrew installed, if you haven't yet, then install PHP:
brew install -v homebrew/php/php70 --enable-embed=shared
However, I haven't tested this on MacOS so YMMV. You will most likely need to add the full path to the include/php7
directory that Brew uses into the php7.go
file, or wait for a branch for adding MacOS support.
I installed php shared library and added the full path. now the error appears like this.
# github.com/deuill/go-php/engine
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:8:72: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static zval *_receiver_get(zval *object, zval *member, int type, const zend_literal *key);
^~~~~~~~~~~~
zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:9:74: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static void _receiver_set(zval *object, zval *member, zval *value, const zend_literal *key);
^~~~~~~~~~~~
zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:10:74: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static int _receiver_exists(zval *object, zval *member, int check, const zend_literal *key);
^~~~~~~~~~~~
zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:13:86: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static zend_function *_receiver_method_get(zval **object, char *name, int len, const zend_literal *key);
^~~~~~~~~~~~
zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:17:8: error: unknown type name 'zend_object_value'
static zend_object_value _receiver_init(zend_class_entry *class_type);
^
5 errors generated.
Did you build with -tags php7
?
i.e.:
go build -tags php7
Unfortunately, you'll have to pass that in any build command that includes go-php
, even things that just include it as a dependency. PHP 7.x has been out for a while now, though, so I may just change the default and have PHP 5.x require a tag instead.
I was not using build tags.
With -tags php7
appears like below.
github.com/deuill/go-php/engine
# github.com/deuill/go-php/engine
In file included from engine/context.go:12:
include/context.h:17:10: fatal error: '_context.h' file not found
#include "_context.h"
^
1 error generated.
I believe you may have accidentally removed the following:
#cgo CFLAGS: -Iinclude/php7 -Isrc/php7
Which defines the include paths for the local PHP 7.x headers.
I did the whole process from downloading the "go-php" library and I've got the same error message.
In file included from engine/context.go:12:
include/context.h:17:10: fatal error: '_context.h' file not found
#include "_context.h"
^
1 error generated.
I'm thinking that OS X version of php is very strange because instead of installing in include/php7
dir it's installed in /usr/local/Cellar/php70/7.0.7/include
dir (maybe cos the rootless problem?).
And I couldn't find _context.h
file in any version of php installed.
The _context.h
file is a local include here, and does not belong to PHP itself, hence why you need those relative paths I commented on above, in addition to the absolute paths to /usr/local/Cellar/php70/7.0.7/include
etc.
I'll see if I can find a MacOS machine to test support on.
I think I got that part.. Now I have another message. Let me organize what I've done until now.
At first when I just finished to download and do go build -tags php7
I get this message.
# github.com/deuill/go-php/engine
engine/context.go:11:11: fatal error: 'main/php.h' file not found
#include <main/php.h>
^
1 error generated.
so I change engine/context.go
file's import with full path
// #cgo CFLAGS: -I/usr/local/Cellar/php70/7.0.7/include/php -I/usr/local/Cellar/php70/7.0.7/include/php/main -I/usr/local/Cellar/php70/7.0.7/include/php/TSRM
// #cgo CFLAGS: -I/usr/local/Cellar/php70/7.0.7/include/php/Zend -Iinclude
The new part is here. this is the new message I've got.
github.com/deuill/go-php/engine
# github.com/deuill/go-php/engine
engine/engine.c:43:10: warning: enumeration values 'SAPI_HEADER_DELETE_ALL' and 'SAPI_HEADER_SET_STATUS' not handled in switch [-Wswitch]
# github.com/deuill/go-php/engine
engine/receiver.c:79:1: warning: control reaches end of non-void function [-Wreturn-type]
# github.com/deuill/go-php/engine
engine/value.c:121:47: warning: incompatible pointer types passing 'unsigned long *' to parameter of type 'zend_ulong *' (aka 'unsigned long long *') [-Wincompatible-pointer-types]
include/php7/_value.h:14:87: note: passing argument to parameter 'num_index' here
# github.com/deuill/go-php/engine
ld: library not found for -lphp7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You're getting there! Final piece (hopefully) would require that you go into php7.go
and change that line to this (or similar):
// #cgo LDFLAGS: -L/usr/local/Cellar/php70/7.0.7/lib -lphp7
I assume that's where Homebrew installs the PHP libraries.
The lib path is that you wrote.
I'm tried adding the path but doesn't compile. so I tried changing the depth of the path like
<path from root>/lib
, <path from root>/lib/php
, <path from root>/lib/php/build
but still getting the same message.
It may be that Homebrew installs the libraries as libphp.so
and not libphp7.so
. Check the relevant folders and see what the name of the .so
libraries are. The convention is, a -lphp7
declaration corresponds to a file named libphp7.so
, and so forth.
inside lib
dir looks like this
/lib
└── php
└── build
├── Makefile.global
├── acinclude.m4
├── config.guess
├── config.sub
├── libtool.m4
├── ltmain.sh
├── mkdep.awk
├── phpize.m4
├── run-tests.php
├── scan_makefile_in.awk
└── shtool
next lib
dir there is a libexec
dir which contains apache2/libphp7.so
So I tried variations like
// #cgo LDFLAGS: -L/usr/local/Cellar/php70/7.0.7/libexec/ -lphp7
// #cgo LDFLAGS: -L/usr/local/Cellar/php70/7.0.7/libexec/apache2 -lphp7
but results the same.
Bah, how stupid. It appears that Homebrew does not support building PHP as a shared library. I assumed passing the --enable-embed=shared
option, which works for the PHP source, would be passed in and the libraries installed correctly; it is not.
These are your choices:
php-embed
.yah, actually I couldn't notice that. brew didn't give me any feedback.. I don't understand properly about brew. And I guess docker/VM will not help much. I heard cgo has cross compile difficulty. I'm going to try compiling from source.
hi, I built php from source. Now I have embed lib files but still I have a similar message. I'm thinking to give up and look for another away.
engine/engine.c:43:10: warning: enumeration values 'SAPI_HEADER_DELETE_ALL' and 'SAPI_HEADER_SET_STATUS' not handled in switch [-Wswitch]
engine/engine.c:97:2: warning: incompatible pointer types initializing 'void (*)(char *, int)' with an expression of type 'void (char *)' [-Wincompatible-pointer-types]
# github.com/deuill/go-php/engine
engine/receiver.c:79:1: warning: control reaches end of non-void function [-Wreturn-type]
# github.com/deuill/go-php/engine
engine/value.c:121:47: warning: incompatible pointer types passing 'unsigned long *' to parameter of type 'zend_ulong *' (aka 'unsigned long long *') [-Wincompatible-pointer-types]
include/php7/_value.h:14:87: note: passing argument to parameter 'num_index' here
# github.com/deuill/go-php/engine
ld: library not found for -lphp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Hi guys, how did you succeed to build PHP from source on OS X with "--enable-embed=shared"? I constantly got bunch of errors like this:
clang: error: ext/date/php_date.o: No such file or directory
Tried different ways but still no luck.
I'm not sure if PHP can be built with Clang. If anything, there's probably documentation out there on how to build.
The real outcome of this is I should probably provide binary packages built against PHP statically, but I need to confirm with the PHP license before I can do that.
I built with gcc-6 too, there are some problems with .o / .dyld file locations on OS X when building with "--enable-embed=shared" option. It is a known bug at PHP.net, but nobody cares. If you could, please release static binary, because "shared PHP" is quite hard to achieve on OS X.
Thanks a lot for the package though :)
Hi, I could build PHP on Mac but the problem was to link these files and build with go. now I'm going to look for a way to link ".so" files. I'm not sure if it's possible but could be another way. thanks for the help @deuill
@walker-walks Could you tell how did you compile the PHP in shared mode on OS X, please?
Hi @aaxx . To be honest I don't remember exactly. I mixed up some tutorials to do that. This is what I remember.
Download PHP source file from the official.
configure the make file with build options. like below.
./configure \
--enable-mod-charset \
--with-config-file-path=/etc \
--with-apxs2=/usr/sbin/apxs \
--disable-cgi \
--with-libexpat-dir=/usr \
--with-libxml-dir=/usr \
--with-openssl \
these options are just an example, for detail you can check here.
after configuring make file you do make
, make test
and make install
.
I think it was something like this.
Hi, @deuill . I'm making a portable server to help my graphic designers friends on FrontEnd development with golang/echo framework. https://github.com/walker-walks/quick_serv They said it would be useful if the server executes php files. so I was trying to call and execute php from go in a way I don't have License problem..
So I'm trying to use go-php library but I'm having the same issue with some people when I'm doing
go get
.I don't know if it's correct but, I downloaded the php source file and put the
php-7/main
intogo-php/engine/main
and passed this part and them appeared another error which is.I moved all the files were in
php-7/Zend
togo-php/engine/main
. and Now I have the issue below that I can't understand.I wold be very happy if you could give me any suggestions. thanks.