Author Topic: Building Codeblocks with LLVM Clang error  (Read 5812 times)

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Building Codeblocks with LLVM Clang error
« on: July 05, 2024, 04:31:44 am »
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;
    }

};

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


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?

« Last Edit: July 05, 2024, 04:35:19 am by jeybee »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building Codeblocks with LLVM Clang error
« Reply #1 on: July 05, 2024, 02:49:10 pm »
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

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #2 on: July 05, 2024, 04:44:11 pm »
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;

credit for figuring it out goes to jonas schwoebel

https://stackoverflow.com/questions/64588313/initialization-of-static-template-member-in-crtp/64588437#64588437
« Last Edit: July 05, 2024, 06:15:22 pm by jeybee »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1644
Re: Building Codeblocks with LLVM Clang error
« Reply #3 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'|

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #4 on: July 05, 2024, 05:55:22 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'|

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.

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #5 on: July 05, 2024, 05:56:54 pm »
one thing i noticed is the resource.rc file takes the arch of the machine that it's compiling on and not the host machine it's being compiled for
« Last Edit: July 05, 2024, 06:00:48 pm by jeybee »

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #6 on: July 05, 2024, 05:59:05 pm »
image of codeblocks running on arm32 windows 10

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #7 on: July 05, 2024, 06:00:11 pm »
image of compiling win32 gui tempate app

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1644
Re: Building Codeblocks with LLVM Clang error
« Reply #8 on: July 05, 2024, 06:37:31 pm »
Other managers (editormanager, filemanager...) use the exact same code. Did you change also their code, or they compiled flawlessly?

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #9 on: July 05, 2024, 06:40:50 pm »
Other managers (editormanager, filemanager...) use the exact same code. Did you change also their code, or they compiled flawlessly?

yes all of them needed changing in the same way. no resulting issues with compiling due to it.

Offline jeybee

  • Single posting newcomer
  • *
  • Posts: 8
Re: Building Codeblocks with LLVM Clang error
« Reply #10 on: July 06, 2024, 12:22:25 am »
here is an upload of the source https://github.com/jethrobull/codeblocks-20.03-arm

had to disable the debugger , have not as yet cross compiled drmingw to get the dll's needed. hopefully will get that going soon.

i'll also update here with the wxWidgets-3.1.4 source, after making a few changes was compiled as standard with the
Code
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1
command using the llvm clang here https://github.com/mstorsjo/llvm-mingw/releases/tag/20240619