Extensions calling C++
| From: | John Keiser | Date: | Sun, 09 Jul 2000 19:20:12 +0000 |
| Subject: | Extensions calling C++ | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-23940@lists.php.net to get a copy of this message | ||
Hello all,
I am trying to make an extension that uses a library written in C++.
I have gotten a simple extension working with C (ext_skel and the build
process are really something else, good job!), and my current approach is to
make the .c call a .cpp or .C file which has extern "C" functions in it
calling the C++ lib functions. To this end, I am currently just trying to
get a .c and .C/cpp file to compile together in the extension.
The problem is, the .C or .cpp file does not seem to get compiled at all;
instead it is passed direct on the libtool line.
Is there a better way to do this? My next option is to move the .C file in
question into an external library and compile separately, but it'd be easier
to have the file in the PHP lib where it belongs.
This is what my project looks like (originally generated with ext_skel),
with just pertinent info:
Makefile.in:
------------------
LTLIBRARY_NAME = libsword.la
LTLIBRARY_SOURCES = sword.c sword_int.C
LTLIBRARY_SHARED_NAME = sword.la
include $(top_srcdir)/build/dynlib.mk
------------------
sword.c: generated by ext_skel, only added #include "sword_inc.h" and have
it call browse_int().
sword_inc.h:
------------------
BEGIN_EXTERN_C()
char * browse_int(char * verse);
END_EXTERN_C()
------------------
sword_inc.C:
------------------
#include "php.h"
#include "sword_int.h"
BEGIN_EXTERN_C();
char * browse_int(char * verse) {
char * retval = emalloc(strlen(verse) + 9);
sprintf(retval, "<B>%s:</B>", verse);
return retval;
}
END_EXTERN_C();
------------------
I have tried sword_inc.C with and without the EXTERN_C, but since it isn't
compiling, I'm guessing the point is moot right now :)
It seems like Zend was planning to add C++ support somehow, since the
BEGIN_EXTERN_C macro is defined.
Any help would be appreciated.
--John Keiser