# Support for C++ extension in UNIX builds

- Thread: https://externals.io/message/4099
- Original archive: https://news-web.php.net/php.internals/4099
- Started by Mark Spruiell on 2003-08-19T22:39:22+00:00
- Messages: 8
- 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

---

## #4099 — Mark Spruiell — 2003-08-19T22:39:22+00:00

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

I've written a PHP5 extension in C++ that builds great on Linux with GCC, whether I compile it
into PHP or build it as a shared library.

On Solaris with Sun CC, however, I've had to manually edit the Makefile or the libtool script in
order to successfully build my extension. When I compile the extension into PHP, I have to change
$(CC) to $(CXX) in certain places in the Makefile. When I build it as a dynamic library, I have to
edit libtool so that it uses $(CXX) and not ld to create the shared library.

Am I overlooking some configuration step that eliminates the need to manually edit these files?

Thanks,
- Mark

---

## #4101 — Jani Taskinen — 2003-08-20T03:52:04+00:00

URL: https://externals.io/message/4099#4101 · In reply to: #4099

Add PHP_REQUIRE_CXX to your config.m4
   
   --Jani
    



>I've written a PHP5 extension in C++ that builds great on Linux with GCC, whether I compile it
>into PHP or build it as a shared library.
>
>On Solaris with Sun CC, however, I've had to manually edit the Makefile or the libtool script in
>order to successfully build my extension. When I compile the extension into PHP, I have to change
>$(CC) to $(CXX) in certain places in the Makefile. When I build it as a dynamic library, I have to
>edit libtool so that it uses $(CXX) and not ld to create the shared library.
>
>Am I overlooking some configuration step that eliminates the need to manually edit these files?
>
>Thanks,
>- Mark

---

## #4102 — Mark Spruiell — 2003-08-20T04:35:10+00:00

URL: https://externals.io/message/4099#4102 · In reply to: #4101

>
>    Add PHP_REQUIRE_CXX to your config.m4

Thanks for the reply, but I've already got PHP_REQUIRE_CXX in my config.m4, and I'm setting the
cxx flag in PHP_NEW_EXTENSION. Is there anything else I'm missing?

- Mark

>    --Jani
>
>
> 
>
> > […]

---

## #4103 — Sascha Schumann — 2003-08-20T04:58:10+00:00

URL: https://externals.io/message/4099#4103 · In reply to: #4099

> On Solaris with Sun CC, however, I've had to manually edit the
> Makefile or the libtool script in order to successfully build
> my extension. When I compile the extension into PHP, I have to
> change $(CC) to $(CXX) in certain places in the Makefile.

    *.cpp files are automatically compiled using $(CXX).  Make
    sure that you use the sanctioned suffix.

> When I build it as a dynamic library, I have to edit libtool so
> that it uses $(CXX) and not ld to create the shared library.

    libtool 1.4 does not support building DSOs in a portable way
    for any language but C.  Try libtool 1.5.

    - Sascha

---

## #4110 — Jay Smith — 2003-08-20T14:57:15+00:00

URL: https://externals.io/message/4099#4110 · In reply to: #4099

fwiw, I've never had these problems with gcc's C++ compiler on Solaris when
building C++ extensions, and the final linking step is usually done by gcc,
not g++. When you do the linking, do you link to the stdc++ library? 

J


Mark Spruiell wrote:

> I've written a PHP5 extension in C++ that builds great on Linux with GCC,
> whether I compile it into PHP or build it as a shared library.
> 
> On Solaris with Sun CC, however, I've had to manually edit the Makefile or
> the libtool script in order to successfully build my extension. When I
> compile the extension into PHP, I have to change $(CC) to $(CXX) in
> certain places in the Makefile. When I build it as a dynamic library, I
> have to edit libtool so that it uses $(CXX) and not ld to create the
> shared library.
> 
> Am I overlooking some configuration step that eliminates the need to
> manually edit these files?
> 
> Thanks,
> - Mark

---

## #4134 — Mark Spruiell — 2003-08-22T20:28:35+00:00

URL: https://externals.io/message/4099#4134 · In reply to: #4110

>
> fwiw, I've never had these problems with gcc's C++ compiler on Solaris when
> building C++ extensions, and the final linking step is usually done by gcc,
> not g++. When you do the linking, do you link to the stdc++ library?

Unlike GCC, Sun's C and C++ compilers are independent entities, therefore you
can't link a C++ program or shared library when the C compiler is driving the
linker. It's also not possible to compile PHP's C code with Sun's C++ compiler.

I guess we're a little spoiled by GCC. :)

- Mark

> J
>
>
> Mark Spruiell wrote:
>
> > […]

---

## #4135 — Jay Smith — 2003-08-22T20:36:59+00:00

URL: https://externals.io/message/4099#4135 · In reply to: #4134

Mark Spruiell wrote:
> 
> Unlike GCC, Sun's C and C++ compilers are independent entities, therefore
> you can't link a C++ program or shared library when the C compiler is
> driving the linker. It's also not possible to compile PHP's C code with
> Sun's C++ compiler.
> 
> I guess we're a little spoiled by GCC. :)
> 
> - Mark
> 

I suppose so. I rarely use Sun's compiler so I won't hazard a guess as to
what's going on here. I guess you don't have access to gcc on that machine,
eh?

J

---

## #4136 — Mark Spruiell — 2003-08-22T21:49:53+00:00

URL: https://externals.io/message/4099#4136 · In reply to: #4135

> Mark Spruiell wrote:
> > […]
>
> I suppose so. I rarely use Sun's compiler so I won't hazard a guess as to
> what's going on here. I guess you don't have access to gcc on that machine,
> eh?

GCC works great for me on Linux, but we haven't needed to port our code to GCC
on Solaris yet.

- Mark
