I've been working on some PHP extensions that were written in C++ for a
while now. I wrote the original stuff a while
back, and since I have no great desire to re-write them in C, I decided to
just go ahead and use the C++ instead.

PHP and Apache are both written in C, so there are going to be some obvious
pains involved in getting C++ to work
properly with the C base. (extern "C"'s, linkage problems, etc.)

I managed to get everything to work eventually, but not without a fair
amount of hair pulling and whimpering. In the end, this is
the procedure I came up with:

-- take the library I wrote in C++. Extern "C" a lot of stuff so C code can
see it properly.
-- use ext_skel to make the extension skeleton.
-- write a wrapper for the C++ in C with the stuff the ext_skel produced.
-- modify the config.m4 file ext_skel produces by adding a PHP_REQUIRE_CXX

  Now, for some reason, adding PHP_REQUIRE_CXX doesn't seem to do much, so
I'm probably not using it correctly.
  Even after adding it, I still need to manually edit config_vars.mk so that
it reads:

  CXX = g++
  CXXFLAGS = -g -O2

  I don't know why.

-- modify the Makefile/Makefile.in files to see the new library that's about
to be created by adding

  LTLIBRARY_OBJECTS_X = whatever.lo

-- compile PHP, compile Apache.

  Compiling PHP is fine, as the C++ files are done with g++ (or C++ compiler
X) and the C files with gcc
  (or whatever C compiler). Apache starts to compile fine, but when it hits
PHP, it starts complaining about
  invalid function prototypes and such, especially if I use the STL or
anything of that sort. At this point,
  I have to continue compiling Apache with a C++ compiler, which is easy
enough. (I usually just change the
  compiler in the apache_path/src/Makefile file by changing "CC=gcc" to

  Unfortunately, I can't seem to automate this.

So my question is: is there an easier way? I don't mind having to do all of
this stuff now, but if I have to
do it a bunch of times, it's going to start sucking.


J Smith
pseudo "code, dba and linux guy"
Tutorbuddy Inc.
The Magic Lantern Group

PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to