I´m building a C++ extension to PHP, using a template of config.m4 from this post and this article.
I need to use the C++11 in standard to compile my classes, so I´ve used the EXTRA_FLAGS clause as:
EXTRA_FLAGS="-std=c++11"
in my config.m4. The final code:
PHP_ARG_ENABLE(vehicles,
[Whether to enable the "vehicles" extension],
[ --enable-vehicles Enable "vehicles" extension support])
if test $PHP_VEHICLES != "no"; then
EXTRA_FLAGS="-std=c++11"
PHP_REQUIRE_CXX()
PHP_SUBST(VEHICLES_SHARED_LIBADD)
PHP_ADD_LIBRARY(stdc++, 1, VEHICLES_SHARED_LIBADD)
PHP_NEW_EXTENSION(vehicles, vehicles.cc car.cc, $ext_shared)
fi
This is not working at all (the compiler does not receive the extra flags). I then assume that this EXTRA_FLAGS parameter is not related to the compiler at all, but to the script....
How can I send a flag to the g++ compiler to them him to use C++11 ?
Thanks for helping.
I´ve found a solution. Here is the definitive code:
PHP_ARG_ENABLE(vehicles,
[Whether to enable the "vehicles" extension],
[ --enable-vehicles Enable "vehicles" extension support])
if test $PHP_VEHICLES != "no"; then
CXX_FLAGS="-std=c++0x"
PHP_REQUIRE_CXX()
PHP_SUBST(VEHICLES_SHARED_LIBADD)
PHP_ADD_LIBRARY(stdc++, 1, VEHICLES_SHARED_LIBADD)
PHP_NEW_EXTENSION(vehicles, vehicles.cc car.cc, $ext_shared)
fi
Make sure the CXX_FLAGS
goes before PHP_REQUIRE_CXX()
otherwise it won´t work.
There is also a macro called X_CXX_COMPILE_STDCXX_11([noext], [mandatory])
whose code is here that automates that process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With