# C++ extension question

- Thread: https://externals.io/message/4507
- Original archive: https://news-web.php.net/php.internals/4507
- Started by Igal Ore on 2003-09-17T14:17:54+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4507 — Igal Ore — 2003-09-17T14:17:54+00:00

URL: https://externals.io/message/4507#4507

I developing some extension on m$ platform with M$VC6.0 ( it's a OpenSSL crypto 
capabilities, more advanced than OpenSSL extension providing, when i fill it 
ready i will try to publish to PHP site) when core language for internals is a 
C++, meaning inside implementation of PHP functions there calls to C++ classes; 
may be in future i should actually use PHP object oriented side.

Until than was not much functions it was nice and exciting development , until 
number of functions grow to more than 60 and becomes a little hard to maintain 
in one file. I tried to do very standard thing , segregate functions by they 
functionality to different files , and all seemed to be happy in compilation but 
not in linking;

I'm receiving this
php_TPKCS12.obj : LNK2005 error: _delete already defined in cert.obj
php_TPKCS12.obj : warning LNK4006: _delete already defined in cert.obj; second 
definition ignored

I searched forums of PHP and around for some examples of somebody stuck with 
same problem , but haven't found something similar;
There some references and even explanations how to create PHP extension in C++ 
but there again considering that all PHP functions are defined and implemented 
in one file.

obliviously this is very urgent and not very "hot" issue , but still could 
somebody give a look on this .

Not interesting proposition like search for C function named "delete" is not 
counting. There is no such thing in PHP code and not in my code

My hint (and after some digging in code, another point to have open source code 
for applications) that somewhere in ZEND engine there definition that confusing 
compiler/linker that not protected from header file redefinition problems ...

---

## #4509 — Jay Smith — 2003-09-17T14:27:17+00:00

URL: https://externals.io/message/4507#4509 · In reply to: #4507

I'm assuming "delete" isn't a function but the C++ operator delete. You're
probably #including the same file more than once, but I doubt it's in Zend. 

If all else fails, you can try passing "/FORCE" to the linker options and
it'll try to force the linkage. It might result in a broken binary, though.

J

Igal Ore wrote:

> I developing some extension on m$ platform with M$VC6.0 ( it's a OpenSSL
> crypto capabilities, more advanced than OpenSSL extension providing, when
> i fill it ready i will try to publish to PHP site) when core language for
> internals is a C++, meaning inside implementation of PHP functions there
> calls to C++ classes; may be in future i should actually use PHP object
> oriented side.
> 
> Until than was not much functions it was nice and exciting development ,
> until number of functions grow to more than 60 and becomes a little hard
> to maintain in one file. I tried to do very standard thing , segregate
> functions by they functionality to different files , and all seemed to be
> happy in compilation but not in linking;
> 
> I'm receiving this
> php_TPKCS12.obj : LNK2005 error: _delete already defined in cert.obj
> php_TPKCS12.obj : warning LNK4006: _delete already defined in cert.obj;
> second definition ignored
> 
> I searched forums of PHP and around for some examples of somebody stuck
> with same problem , but haven't found something similar;
> There some references and even explanations how to create PHP extension in
> C++ but there again considering that all PHP functions are defined and
> implemented in one file.
> 
> obliviously this is very urgent and not very "hot" issue , but still could
> somebody give a look on this .
> 
> Not interesting proposition like search for C function named "delete" is
> not counting. There is no such thing in PHP code and not in my code
> 
> My hint (and after some digging in code, another point to have open source
> code for applications) that somewhere in ZEND engine there definition that
> confusing compiler/linker that not protected from header file redefinition
> problems ...

---

## #4510 — Wez Furlong — 2003-09-17T14:48:10+00:00

URL: https://externals.io/message/4507#4510 · In reply to: #4509

This sounds like the "rookie" mistake of declaring your functions inline in
the class definition in the header files, and then including those headers
in multiple files.

eg: foo.h:

class Foo {
  Foo() { ... }
  ~Foo() { ... }
};

foo.cpp:
#include "foo.h"

bar.cpp:
#include "foo.h"

== linker problems.

--Wez.

> I'm assuming "delete" isn't a function but the C++ operator delete. You're
> probably #including the same file more than once, but I doubt it's in
Zend.
>
> If all else fails, you can try passing "/FORCE" to the linker options and
> it'll try to force the linkage. It might result in a broken binary,
though.
> Igal Ore wrote:
>
> > […]

---

## #4511 — Igal Ore — 2003-09-17T15:01:26+00:00

URL: https://externals.io/message/4507#4511 · In reply to: #4510

you are right , and for those cases there a preprocessor protection
#ifndef DO_NOT_MAKE_BOBO
#define DO_NOT_MAKE_BOBO

class Foo{
	Foo(){...}
	~Foo(){...}
};
#endif


isn't it?

Wez Furlong wrote:
> This sounds like the "rookie" mistake of declaring your functions inline in
> the class definition in the header files, and then including those headers
> in multiple files.
> 
> eg: foo.h:
> 
> class Foo {
>   Foo() { ... }
>   ~Foo() { ... }
> };
> 
> foo.cpp:
> #include "foo.h"
> 
> bar.cpp:
> #include "foo.h"
> 
> == linker problems.
> 
> --Wez.
> 
> 
> > […]
> 
> Zend.
> 
> > […]
> 
> though.
> 
> > […]

---

## #4513 — Wez Furlong — 2003-09-17T15:05:37+00:00

URL: https://externals.io/message/4507#4513 · In reply to: #4511

No, that only prevents the file being included twice in the same .cpp file.
The solution to this problem is to move the function bodies into their own
.cpp file:

foo.h:
class Foo {
Foo();
~Foo();
};

fooclass.cpp:
Foo::Foo() { ... }
Foo::~Foo() { ... }

--Wez.


----- Original Message ----- 
From: "Igal Ore" <iore@cipherquest.com>
To: <internals@lists.php.net>; "Wez Furlong" <wez@thebrainroom.com>
Cc: <jay@php.net>; <internals@lists.php.net>
Sent: Wednesday, September 17, 2003 4:01 PM
Subject: Re: [PHP-DEV] Re: C++ extension question


> you are right , and for those cases there a preprocessor protection
> #ifndef DO_NOT_MAKE_BOBO
> #define DO_NOT_MAKE_BOBO
>
> class Foo{
> Foo(){...}
> ~Foo(){...}
> };
> #endif
>
>
> isn't it?
>
> Wez Furlong wrote:
> > […]
in
> > […]
headers
> > […]

---

## #4514 — Igal Ore — 2003-09-17T15:16:29+00:00

URL: https://externals.io/message/4507#4514 · In reply to: #4513

yes you right again  , but as i suggested , adn thinking that problem is 
existin in this scenatrio
cert.cpp (main file with all PHP required defitions and becoming a big 
source file; all php includes surrounded by extern "C" {})
php_TPKCS12.cpp have only functions related to PKCS#12 treating 
(encypted file storage for end user certificates, private keys and etc.)
meaning in this file there implementation for php functions dealing with p12

And there i have a problem , at least i think.

After brief verification i'm do not use in second file and Classes 
associated with problem that you mentioned.

Wez Furlong wrote:

>No, that only prevents the file being included twice in the same .cpp file.
>The solution to this problem is to move the function bodies into their own
>.cpp file:
>
>foo.h:
>class Foo {
>Foo();
>~Foo();
>};
>
>fooclass.cpp:
>Foo::Foo() { ... }
>Foo::~Foo() { ... }
>
>--Wez.
>
>
>----- Original Message ----- 
>From: "Igal Ore" <iore@cipherquest.com>
>To: <internals@lists.php.net>; "Wez Furlong" <wez@thebrainroom.com>
>Cc: <jay@php.net>; <internals@lists.php.net>
>Sent: Wednesday, September 17, 2003 4:01 PM
>Subject: Re: [PHP-DEV] Re: C++ extension question
>
>
>  
>
> > […]
>in
>  
>
> > […]
>headers
>  
>
> > […]
