2

Reading this post and this article I got my first PHP extension up and running.

Here is the config.m4 file from the article that I used (to keep it clear I kept the same vehicles and car class names from the article, although my real classes has different names):

PHP_ARG_ENABLE(vehicles,
    [Whether to enable the "vehicles" extension],
    [  --enable-vehicles      Enable "vehicles" extension support])

if test $PHP_VEHICLES != "no"; then
    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

What I need now is to move o another level of code organization as follow:

a) Moving the carclass to a common vehicle class folder with other vehicle classes (truck, bus, etc.)

b) Build a shared library will all of those classes

c) Call that shared library class from PHP

So, I would have the following directory structure like:

vehicles -> src = The .cpp classes and include files

vehicles -> lib = The vehicle.so shared library

How do I modify the config.m4 to work with this structure, considering all the vehicle´s classes include files from the original paths and including the shared .so library to the final built.

Thanks for helping.

1 Answer 1

1

PHP_ADD_LIBRARY_WITH_PATHdid the trick. Use it as many times as you need to (for adding multiple libraries).

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

    PHP_ADD_LIBRARY_WITH_PATH(libraryname1, /etc/whatever_path_to_library, VEHICLES_SHARED_LIBADD)
    PHP_ADD_LIBRARY_WITH_PATH(libraryname2, /etc/whatever_path_to_library, VEHICLES_SHARED_LIBADD)
    PHP_ADD_LIBRARY_WITH_PATH(libraryname3, /etc/whatever_path_to_library, VEHICLES_SHARED_LIBADD)

    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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.