CopernicaMarketingSoftware / PHP-CPP

Library to build PHP extensions with C++
http://www.php-cpp.com/
Apache License 2.0
1.43k stars 333 forks source link

Compile error under mac... #255

Open yarcowang opened 8 years ago

yarcowang commented 8 years ago
In file included from zend/includes.h:72:
zend/../include/streams.h:24:8: error: thread-local storage is not supported for the current target
extern thread_local PHPCPP_EXPORT std::ostream out;
       ^
zend/../include/streams.h:25:8: error: thread-local storage is not supported for the current target
extern thread_local PHPCPP_EXPORT std::ostream error;
       ^
zend/../include/streams.h:26:8: error: thread-local storage is not supported for the current target
extern thread_local PHPCPP_EXPORT std::ostream notice;
       ^
zend/../include/streams.h:27:8: error: thread-local storage is not supported for the current target
extern thread_local PHPCPP_EXPORT std::ostream warning;
       ^
zend/../include/streams.h:28:8: error: thread-local storage is not supported for the current target
extern thread_local PHPCPP_EXPORT std::ostream deprecated;
       ^
5 errors generated.
make: *** [shared/zend/base.o] Error 1

mac version 10.10.5 php installed from homebrew:

yarco@me PHP-CPP$ brew info php70
homebrew/php/php70: stable 7.0.8 (bottled), HEAD
PHP Version 7.0
https://php.net
willianszwy commented 8 years ago

hi, I changed the default compiler to the g++-6 (installed by brew )

yarcowang commented 8 years ago

After upgrade to g++-6, then do CXX=g++-6 make, i got:

...
g++-6 -Wall -c -std=c++11 -fvisibility=hidden -DBUILDING_PHPCPP -Wno-write-strings -g `php-config --includes` -fpic -o shared/zend/zval.o zend/zval.cpp
/usr/local/bin/php-config: line 43: /usr/local/Library/ENV/4.3/sed: No such file or directory
g++-6 -shared -g `php-config --ldflags` -Wl,-soname,libphpcpp.so.2.0 -o libphpcpp.so.2.0.0 shared/common/modifiers.o shared/common/streambuf.o shared/zend/base.o shared/zend/callable.o shared/zend/classbase.o shared/zend/classimpl.o shared/zend/constant.o shared/zend/constantfuncs.o shared/zend/eval.o shared/zend/exception_handler.o shared/zend/exists.o shared/zend/extension.o shared/zend/extensionimpl.o shared/zend/fatalerror.o shared/zend/file.o shared/zend/function.o shared/zend/functor.o shared/zend/global.o shared/zend/globals.o shared/zend/hashmember.o shared/zend/ini.o shared/zend/inivalue.o shared/zend/iteratorimpl.o shared/zend/members.o shared/zend/module.o shared/zend/namespace.o shared/zend/object.o shared/zend/sapi.o shared/zend/script.o shared/zend/streambuf.o shared/zend/streams.o shared/zend/super.o shared/zend/value.o shared/zend/valueiterator.o shared/zend/zendcallable.o shared/zend/zval.o
/usr/local/bin/php-config: line 43: /usr/local/Library/ENV/4.3/sed: No such file or directory
ld: unknown option: -soname
collect2: error: ld returned 1 exit status
make: *** [libphpcpp.so.2.0.0] Error 1
willianszwy commented 8 years ago

Change -soname to -install_name

yarcowang commented 8 years ago

After change lineno 179 (makefile) from

    ${LINKER} ${PHP_LINKER_FLAGS} -Wl,-soname,libphpcpp.so.$(SONAME) -o $@ ${COMMON_SHARED_OBJECTS} ${PHP_SHARED_OBJECTS}

To

    ${LINKER} ${PHP_LINKER_FLAGS} -Wl,-install_name,libphpcpp.so.$(SONAME) -o $@ ${COMMON_SHARED_OBJECTS} ${PHP_SHARED_OBJECTS}

Then i got this:

      Php::StreamBuf::sync()    in streambuf.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [libphpcpp.so.2.0.0] Error 1

Maybe i shouldn't compile it under mac?

willianszwy commented 8 years ago

you need add -undefined dynamic_lookup to LINKER_FLAGS

yarcowang commented 8 years ago

@willianszwy Yes, finally make it done.

Here are the steps for those who want to compile it under mac.

  1. You should use gcc version of the c++ compiler g++-6 (not the apple one, clang++)
  2. You should change lineno(in makefile) 119 to add -undefined dynamic_lookup config like the document said, so the LINKER_FLAGS becomes: LINKER_FLAGS = -shared -undefined dynamic_lookup
  3. You should also change lineno(in makefile) 179 from -soname to install_name, so the that line becomes: ${LINKER} ${PHP_LINKER_FLAGS} -Wl,-install_name,libphpcpp.so.$(SONAME) -o $@ ${COMMON_SHARED_OBJECTS} ${PHP_SHARED_OBJECTS}
  4. Finally you run it as CXX=g++-6 make
  5. Done
yarcowang commented 8 years ago

Forgot to say thank you, @willianszwy