2

I'm trying to make a custom session handler for PHP. (I didn't find a clear documentation about that. If you have a good links, I will be happy to read it ;) )

So when I try to use a zend function like zend_string_init Example

PS_READ_FUNC(mongo)
{
    MongoClient *pMongoClient = static_cast<MongoClient*>(PS_GET_MOD_DATA());
    if(pMongoClient == nullptr)
        return FAILURE;

    std::string strSessionId = (char *)key;
    std::string strSessionData = pMongoClient->read(strSessionId);

    *val = zend_string_init(strSessionData.c_str(), strSessionData.size(), true); //generate a unreference error on __zend_malloc and _emalloc
    return SUCCESS;

}

To build my linker dependency list I use theses line in my makefile

PHP_LINKER_DEPENDENCIES =   $(shell php-config --libs)
> php-config --libs
-lcrypt -lresolv -lcrypt -lz -lpcre -lrt -lm -ldl -lnsl -lxml2 -lssl -lcrypto -lcrypt -lcrypt

The linking command with the error

g++ -L/usr/lib/php/20151012 -L/usr/lib/x86_64-linux-gnu  -o session_storage.so main.o  -lcrypt -lresolv -lcrypt -lz -lpcre -lrt -lm -ldl -lnsl -lxml2 -lssl -lcrypto -lcrypt -lcrypt -L/usr/local/lib -lsasl2 -lssl -lcrypto -lrt -lmongoc-1.0 -lbson-1.0 -lphpcpp

session_storage.o: dans la fonction « zend_string_alloc »:
/usr/include/php/20151012/Zend/zend_string.h:121: référence indéfinie vers « __zend_malloc »
/usr/include/php/20151012/Zend/zend_string.h:121: référence indéfinie vers « _emalloc »

So I don't find the library I need to link with.

Edit about duplicate issue:

I thinks, it's not a duplicate question. The related question is about "what is the error undefined reference ...".

I knows what is this kind of error. I just don't not find the library I need to link with. It's probably a part of zend engine but I'm not sure.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
David
  • 1,177
  • 3
  • 11
  • 26
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – user657267 May 30 '16 at 09:23
  • An undefined reference linkage error is one thing. The linker not finding a library is an entirely different thing, and as you haven't posted the failing linker commandline or the errors that follow from we're in the dark as to what your problem actually is. – Mike Kinghan May 30 '16 at 09:46
  • I have added my link command line `g++ -L/usr/lib/php/20151012 -L/usr/lib/x86_64-linux-gnu -o session_storage.so main.o -lcrypt -lresolv -lcrypt -lz -lpcre -lrt -lm -ldl -lnsl -lxml2 -lssl -lcrypto -lcrypt -lcrypt -L/usr/local/lib -lsasl2 -lssl -lcrypto -lrt -lmongoc-1.0 -lbson-1.0 -lphpcpp ` – David May 30 '16 at 09:51

1 Answers1

1

I found the problem. I build my project like an executable but PHP require a library so.... Add -shared to my build option fix the problem. Thanks for your help

David
  • 1,177
  • 3
  • 11
  • 26