User forums > Help

Building Codeblocks with LLVM Clang error

(1/3) > >>

jeybee:
I'm trying to build codeblocks with llvm clang, this has to be used as i am cross compiling. i've hit a snag that i can't figure out how to work around it

it's related to the manager.h


--- Code: ---template <class MgrT> class DLLIMPORT Mgr
{
    static MgrT *instance;
    static bool isShutdown;
    explicit Mgr(const Mgr<MgrT>&)         { ; };
    Mgr<MgrT>& operator=(Mgr<MgrT> const&) { ; };

protected:

    Mgr()          { assert(Mgr<MgrT>::instance == nullptr); }
    virtual ~Mgr() { Mgr<MgrT>::instance = nullptr; }


public:

    static bool Valid() { return instance; }

    static MgrT* Get()
    {
        if (instance == nullptr)
        {
            if (isShutdown == false)
                instance = new MgrT();
            else
                cbAssert(false && "Calling Get after the subsystem has been shutdown is an error!");
        }
        return instance;
    }

    static void Free()
    {
        isShutdown = true;
        delete instance;
        instance = nullptr;
    }

};
--- End code ---


--- Code: ---template<> ColourManager* Mgr<ColourManager>::instance = nullptr;
template<> bool  Mgr<ColourManager>::isShutdown = false;
--- End code ---


cbcolourmanager.cpp|18|error: explicit specialization of 'instance' after instantiation|

how can i modify the code to get around this issue. i understand i need to declare the explicit specialization.. but how can i do this? how do i modify the header in such a way that this satisfies the c++ standard that llvm clang is trying to adhere to?

stahta01:
I did not see that error under MSys2 CLANG64 which uses

--- Code: ---$ clang --version
clang version 18.1.8
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/clang64/bin

--- End code ---

Tim S.

jeybee:
the fix for anyone encountering this error in the future is


--- Code: ---template<class ColourManager> ColourManager* Mgr<ColourManager>::instance = nullptr;
template<class ColourManager> bool  Mgr<ColourManager>::isShutdown = false;
--- End code ---

credit for figuring it out goes to jonas schwoebel

https://stackoverflow.com/questions/64588313/initialization-of-static-template-member-in-crtp/64588437#64588437

Miguel Gimenez:
With said change cbcolourmanager.cpp compiles, but when compiling the whole project you get this error (tested with MinGW):

--- Code: ---manager.h|224|undefined reference to `Mgr<ColourManager>::isShutdown'|
--- End code ---

jeybee:

--- Quote from: Miguel Gimenez on July 05, 2024, 05:31:06 pm ---With said change cbcolourmanager.cpp compiles, but when compiling the whole project you get this error (tested with MinGW):

--- Code: ---manager.h|224|undefined reference to `Mgr<ColourManager>::isShutdown'|
--- End code ---

--- End quote ---

with llvm clang it compiles and is a usable app. just ported this to arm32, running on the microsoft surface 1/2 nvidia arm soc.

Navigation

[0] Message Index

[#] Next page

Go to full version