# Building C++ extensions

- Thread: https://externals.io/message/25827
- Original archive: https://news-web.php.net/php.internals/25827
- Started by Stut on 2006-09-25T21:09:55+00:00
- Messages: 5
- 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

---

## #25827 — Stut — 2006-09-25T21:09:55+00:00

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

Ok, so I've built an extension that uses a C++ library. It compiles fine 
but the build system is insisting on linking with gcc no matter what I 
tell it. Is there some simple trick I'm missing as far as convincing it 
to use g++ goes?

Here is the config.m4 in case I've missed something in there...

PHP_ARG_ENABLE(mmsr, whether to enable mmsr support,
[  --enable-mmsr=dir       Enable mmsr support])

if test "$PHP_MMSR" != "no"; then
   PHP_ADD_LIBRARY_WITH_PATH(mmsr, "$PHP_MMSR")
   PHP_ADD_INCLUDE("$PHP_MMSR/MMSR")
   PHP_NEW_EXTENSION(mmsr, mmsr.c "$PHP_MMSR/MMSR/mmsr_bridge.cpp", 
$ext_shared)
   PHP_REQUIRE_CXX()
fi

I had expected the PHP_REQUIRE_CXX() macro to trigger a change to the 
link command, but it does not seem to have done anything beyond 
influencing what is used to compile the extension itself.

-Stut

---

## #25828 — Antony Dovgal — 2006-09-25T21:17:37+00:00

URL: https://externals.io/message/25827#25828 · In reply to: #25827

> Ok, so I've built an extension that uses a C++ library. It compiles fine 
> but the build system is insisting on linking with gcc no matter what I 
> tell it. Is there some simple trick I'm missing as far as convincing it 
> to use g++ goes?
> 
> Here is the config.m4 in case I've missed something in there...
> 
> PHP_ARG_ENABLE(mmsr, whether to enable mmsr support,
> [  --enable-mmsr=dir       Enable mmsr support])
> 
> if test "$PHP_MMSR" != "no"; then
>    PHP_ADD_LIBRARY_WITH_PATH(mmsr, "$PHP_MMSR")
>    PHP_ADD_INCLUDE("$PHP_MMSR/MMSR")
>    PHP_NEW_EXTENSION(mmsr, mmsr.c "$PHP_MMSR/MMSR/mmsr_bridge.cpp", 
> $ext_shared)
>    PHP_REQUIRE_CXX()
> fi
> 
> I had expected the PHP_REQUIRE_CXX() macro to trigger a change to the 
> link command, but it does not seem to have done anything beyond 
> influencing what is used to compile the extension itself.

PECL/rar is C++ (or sort of C++) extension, so you can use its config.m4 as an example.
Here it is: http://cvs.php.net/viewvc.cgi/pecl/rar/config.m4?revision=1.6&view=markup

-- 
Wbr, 
Antony Dovgal

---

## #25829 — Olivier Hill — 2006-09-25T21:25:12+00:00

URL: https://externals.io/message/25827#25829 · In reply to: #25827

>
> I had expected the PHP_REQUIRE_CXX() macro to trigger a change to the
> link command, but it does not seem to have done anything beyond
> influencing what is used to compile the extension itself.

Hi,

I think you have to add stdc++ with PHP_ADD_LIBRARY().

I do have a C++ ext internally here, and it still try to link with gcc
and not g++. Still, it does work.

Sincerely,
Olivier

---

## #25830 — Sara Golemon — 2006-09-26T01:36:55+00:00

URL: https://externals.io/message/25827#25830 · In reply to: #25827

>   PHP_NEW_EXTENSION(mmsr, mmsr.c "$PHP_MMSR/MMSR/mmsr_bridge.cpp", 
> $ext_shared)

PHP_NEW_EXTENSION(mmsr, mmsr.c "$PHP_MMSR/MMSR/mmsr_bridge.cpp", 
$ext_shared,,,1)

Ref: aclocal.m4 / EEPHP:Chapter 17

-Sara

---

## #25833 — Stut — 2006-09-26T09:14:39+00:00

URL: https://externals.io/message/25827#25833 · In reply to: #25830

Sara Golemon wrote:
> > […]
>
> PHP_NEW_EXTENSION(mmsr, mmsr.c "$PHP_MMSR/MMSR/mmsr_bridge.cpp", 
> $ext_shared,,,1)
>
> Ref: aclocal.m4 / EEPHP:Chapter 17

Thanks to all who replied. I have it working now.

Sara: I have ordered your book, but this couldn't wait until it arrives.

Thanks again.

-Stut
