# Writing an extension - dyld: ...Symbol not found

- Thread: https://externals.io/message/59565
- Original archive: https://news-web.php.net/php.internals/59565
- Started by Luke Scott on 2012-04-09T21:54:23+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #59565 — Luke Scott — 2012-04-09T21:54:23+00:00

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

I'm writing an extension called "V8PHP". It's similar to the V8JS extension,
but the implementation is quite different.

I'm having trouble linking the v8 library to my extension. When I run a PHP
script via CLI I get:


dyld: lazy symbol binding failed: Symbol not found: __ZN2v86String3NewEPKci
  Referenced from: /phpdev/lib/php/extensions/debug-zts-20090626/v8php.so
  Expected in: flat namespace

dyld: Symbol not found: __ZN2v86String3NewEPKci
  Referenced from: /phpdev/lib/php/extensions/debug-zts-20090626/v8php.so
  Expected in: flat namespace

Trace/BPT trap


I have PHP installed in /phpdev/ (--prefix=/phpdev). v8 was compiled with
gyp using the following commands:

cd /v8/
make dependencies
make native

And this outputted these files to /v8/out/native/:

libpreparser_lib.a
libv8_base.a
libv8_nosnapshot.a
libv8_snapshot.a
obj/
obj.target/

And the obj.target directory has a bunch of .a files in
obj.target/v8_base/src/.

I created a soft link from /v8/include/v8.h to /phpdev/include/v8.h,
/v8/include/v8stdint.h to /phpdev/include/v8stdint.h, and
/v8/out/native/libv8_base.a to /phpdev/lib/libv8.a.

My config.m4 file looks like this:

PHP_ARG_ENABLE(v8php,
    [V8PHP],
    [--enable-v8php      Include V8 JavaScript Engine])

if test $PHP_V8PHP != "no"; then
    SEARCH_PATH="$prefix /usr/local /usr"
    SEARCH_FOR="/include/v8.h"
  
    if test -r $PHP_V8PHP/$SEARCH_FOR; then
        V8_DIR=$PHP_V8PHP
    else
        AC_MSG_CHECKING([for V8 files in default path])
        for i in $SEARCH_PATH ; do
            if test -r $i/$SEARCH_FOR; then
                V8_DIR=$i
                AC_MSG_RESULT(found in $i)
            fi
        done
    fi

    if test -z "$V8_DIR"; then
        AC_MSG_RESULT([not found])
        AC_MSG_ERROR([Unable to locate V8])
    fi

    PHP_ADD_INCLUDE($V8_DIR/include)
    PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_DIR/$PHP_LIBDIR, V8PHP_SHARED_LIBADD)
    PHP_SUBST(V8PHP_SHARED_LIBADD)
    PHP_REQUIRE_CXX()
    PHP_NEW_EXTENSION(v8php, v8php.cc v8_class.cc, $ext_shared)
fi

It _seems_ like libv8.a is trying to link to something else... but I'm not
sure. My extension compiled fine.

I'm on Mac OS X 10.6.x.

Anyone know what the problem could be?

Luke

---

## #59579 — Luke Scott — 2012-04-09T23:11:54+00:00

URL: https://externals.io/message/59565#59579 · In reply to: #59565

> I'm writing an extension called "V8PHP". It's similar to the V8JS extension,
> but the implementation is quite different.
> 
> ...
> 
> Anyone know what the problem could be?
> 
> Luke

I figured out that v8 was being compiled in 32 bit mode... Apparently it
thinks "native" means 32 bit... Recompiled as 64 bit and now I'm getting
this:

PHP Warning:  PHP Startup: Unable to load dynamic library
'/phpdev/lib/php/extensions/debug-zts-20090626/v8php.so' -
dlopen(/phpdev/lib/php/extensions/debug-zts-20090626/v8php.so, 9): Symbol
not found: __ZN2v88internal8Snapshot13context_size_E
  Referenced from: /phpdev/lib/php/extensions/debug-zts-20090626/v8php.so
  Expected in: flat namespace
 in /phpdev/lib/php/extensions/debug-zts-20090626/v8php.so in Unknown on
line 0


Luke
