deuill / go-php

PHP bindings for the Go programming language (Golang)
MIT License
925 stars 105 forks source link

"not a dynamic executable" #39

Closed lexesv closed 7 years ago

lexesv commented 7 years ago

Hello Do you plan to add the possibility of building a portable application? --ldflags '-extldflags "-static"'

deuill commented 7 years ago

I've added provisional support for building against a static PHP 7.x library, but am still fixing some issues with receiver bindings. The plan is to build a binary distribution of go-php that doesn't require building or downloading the PHP library.

lexesv commented 7 years ago

Thank you, but

/dev/go/src/php$ ldd php
    linux-vdso.so.1 (0x00007ffea81fa000)
    libphp7.so => /usr/lib/libphp7.so (0x00007fa2f84a9000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa2f82a5000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa2f7fa4000)
    libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007fa2f7d3a000)
    libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fa2f78d6000)
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007fa2f768c000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fa2f7475000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fa2f7207000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fa2f6fec000)
    libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007fa2f6c85000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa2f6a68000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2f66bd000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fa2f6486000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa2f627e000)
    libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fa2f6066000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fa2f8ba4000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fa2f5e3c000)
    liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fa2f5c19000)

if build

alex@NFS:~/dev/go/src/php$ go build --ldflags '-extldflags "-static"'
# php
/home/alex/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lphp7.0
/tmp/go-link-026755085/000002.o: In function `_cgo_7a2d42f1a351_C2func_getaddrinfo':
/tmp/workdir/go/src/net/cgo_unix.go:66: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status

Please, could you describe process of building a static application?

Debian 8

  1. aptitude install libphp7.0-embed php7.0-dev
  2. go get github.com/deuill/go-php
  3. write a test application.
  4. if go build - ldd not return "not a dynamic executable" if go build --ldflags '-extldflags "-static"' - return error
lexesv commented 7 years ago

And another question, you do not make it possible use a custom php.ini?

deuill commented 7 years ago

If you're building against Debian, you can build using the following:

go build -tags "php7 debian"

You do not need to pass in --ldflags '-extldflags "-static"' etc. By default, Go produces static binaries, but can only statically link against C libraries provided as .a files (which libphp7.0-embed is not).

You can, however, build PHP as a static binary yourself and try to build with:

go build -tags "static"

There are some issues with receiver bindings when statically linking, a bugfix is underway.

lexesv commented 7 years ago

Well thank you.

However, please review this information at these links:

Statically compiled Go programs, always, even with cgo, using musl https://dominik.honnef.co/posts/2015/06/go-musl/

Compile statically linked with musl as an alternative to the non cgo version https://github.com/hlandau/acme/issues/113