CopernicaMarketingSoftware / PHP-CPP

Library to build PHP extensions with C++

Home Page:http://www.php-cpp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple cpp files

gtamas opened this issue · comments

@EmielBruijntjes

I'm not sure if this is related to the library. When using multiple cpp files (e.g: one for each class) and multiple header files, is there anything special I have to do to make it work with PHP?

My code compiles without errors, but PHP fails to load the extension because of an undefined symbol.

The PHP error I'm getting is this:

PHP Startup: Unable to load dynamic library 'aspose_php.so' (tried: /usr/lib/php/20190902/aspose_php.so (/usr/lib/php/20190902/aspose_php.so: undefined symbol: _ZTVN9AsposePhp12PresentationE)...

My code (The Presentation class which PHP cannot find):

presentation.h

#include <phpcpp.h>
#include "../include/aspose.h"

#ifndef PRESENTATION_H
#define PRESENTATION_H

namespace AsposePhp {

    class Presentation : public Php::Base
    {
    private:
       System::SharedPtr<Aspose::Slides::Presentation> _pres;

    public:
        Presentation();
        virtual ~Presentation();
    
        void __construct(Php::Parameters &params);

        Php::Value open(Php::Parameters &params);
        Php::Value get_Count();
    };
}

#endif

presentation.cpp

#include "../include/aspose.h"
#include "../include/functions.h"
#include "../include/presentation.h"
#include "../include/util.h"
#include <phpcpp.h>

using namespace Aspose::Slides;
using namespace System;

namespace AsposePhp {

    void Presentation::__construct(Php::Parameters &params)
    {
    // Method code

    }

    Php::Value Presentation::open(Php::Parameters &params) {
     // Method code
    }


    Php::Value Presentation::get_Count() {
     // Method code
    }


}

And then in main.cpp I do this:

        static Php::Extension extension("pptparser", "1.0");

        Php::Class<AsposePhp::Presentation> ppt("Presentation");

        ppt.method<&AsposePhp::Presentation::open>("open", { });

        ppt.method<&AsposePhp::Presentation::__construct>("__construct", { });

        ppt.method<&AsposePhp::Presentation::get_Count>("get_Count", {});

        extension.add(std::move(ppt));

The linker works fine too:

g++ -shared -fuse-ld=gold -o build/aspose_php.so main.o src/presentation.o src/functions.o -lphpcpp -lAspose.Slides_clang3_libstdcpp -laspose_cpp_clang3_libstdcpp -L../aspose-slides-cpp-linux-20.10//lib

So the presentation.o is there, then how is it an undefined symbol?

Please somebody help :)

Solved. Constructs were not initialised properly.