简体   繁体   中英

Windows vs. Linux vs. Mac: Different php extensions with same struct name and some shared files

I have two php extensions -- A and B.

In ah I have:

struct foo : public functor {
    virtual void operator()( some parameters ); 
};

In bh, I also have the same thing

struct foo : public functor {
    virtual void operator()( some parameters ); 
};

Functor is declared in shared.h which is shared between the two extensions

struct functor {
    virtual void operator()( some parameters );
};

void foo::operator()(some parameters) are implemented differently in a2.cpp and b2.cpp.

In a1.cpp, I have a list of functors used in extension A:

const functor a_func[] = {
    func1(new func1),
    func2(new func2),
    foo(new foo),
    func4(new func4)
};

In b2.cpp, I have a similar list:

const functor b_func[] = {
    func1(new func1),
    foo(new foo),
    func3(new func3),
    func4(new func4)
};

The function foo is called in shared.cpp

const functor* func = get_func( functors );
*func( some arguments );

Where 'functors' is either a_func or b_func, and shared.cpp is called from extension A or extension B depending on the API you're using.

The problem I'm currently facing right now is that when testing extension B on Mac and when extension A is loaded before extension B in php.ini, the foo function defined in a2.cpp is used instead of b2.cpp. But if I reverse the order in php.ini, everything works fine. When I debug into it, I see that the list of functors being passed into get_func() is correct (ie, b_func).

I tried using namespace or renaming the foo function in A and B which fixes the problem. But the thing I'm confused about is the extensions have always worked on Windows and Linux, however now it has this one name definition problem on Mac.

Just in case other people are wondering. This is because MacOS has a default configuration of flat namespace. To fix this, you need to put in MACOSX_DEPLOYMENT_TARGET= sw_vers -productVersion in your config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM