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.

3
  • 1
    Possible duplicate of What is an undefined reference/unresolved external symbol error and how do I fix it? Commented May 30, 2016 at 9: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. Commented May 30, 2016 at 9: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 Commented May 30, 2016 at 9:51

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.