Search code examples
c++githubgcccmakemingw-w64

'variable' declared as an 'inline' field


The Github repository for the sourcecode in question is here: https://github.com/arishackstv/cubemod

For reference this is a mod for the game Cubeworld I am attempting to modify to my own tastes.

The repository has a CMakeLists.txt which I used to generate a MinGW makefile since the creator says the mod was built in release mode using MinGW. Here's my CMake configuration using his CMakeLists.txt: CMake Configuration

It seemed to generate the makefile with no issues, so I attempted to make. I was greeted with the following errors: Errors

The vast majority of the errors are along the lines of:

In file included from C:\Users\[username]\Desktop\cubemod-master\src\core\main.cpp:18:0:C:/Users/[username]/Desktop/CUBEMO~1/src/core/hook/hooks/artifact/display/hook_artifact_display_roundf.h:9:22: error: 'hook' declared as an 'inline' field   static inline Hook* hook;

Very many of these inline field errors. The specific code that generates the specific above error is this:

#pragma once

#include <hook/hook.h>
#include <game_structures.h>
#include "hook_concat_artifact_suffix.h"

class Hookroundf : public Hook
{
    static inline Hook* hook;

    //This is literally only called from the artifact display thing so it's fine
    static float HOOK cube_roundf(float f)
    {
        //Get actual artifact stats
        return Main::GetInstance().GetLocalPlayer()->GetIncreasedArtifactStats((ArtifactType)HookConcatArtifactSuffix::artifact_index, true);
    }

public:
    Hookroundf() : Hook(MemoryHelper::GetCubeBase() + 0x275760, (void*)cube_roundf, hook)
    {}
};

The actual compiled releases from this guy's Github actually do work, I've tried them, so I find it strange that his source code runs into compilation errors. I'm wondering if it's coming down to my build environment not being set up correctly? If anyone IS able to successfully compile this code, I'd love to hear your steps to see what I got wrong. And if it's actually truly the case that this source code is faulty, I'd love to hear about what can be done to fix it. Aren't static inline fields a c++ 17 thing? Perhaps that's it? Though I tried specifying -std=C++17 in the CMAKE_CXX_FLAGS but that didn't seem to do it.

EDIT: The recommendations to upgrade my gcc version were extremely helpful. After updating gcc to the newest available version (9.20), the errors related to unavailble C++ features like the inline variables were fixed! There are now a few more errors, but they are much fewer in number. Here is our new output from attempting a make:

C:\Users\[username]\Desktop\cubemod-master\BUILD_>make
Scanning dependencies of target cubemod
[ 33%] Building CXX object CMakeFiles/cubemod.dir/src/dllmain.cpp.obj
[ 66%] Building CXX object CMakeFiles/cubemod.dir/src/core/main.cpp.obj
[100%] Linking CXX shared library ..\bin\cubemod.cwmod
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\cubemod.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2f): undefined reference to `xed_operand_values_set_mode'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\cubemod.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN4Hook11InstallHookEv[__ZN4Hook11InstallHookEv]+0x11): undefined reference to `xed_tables_init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: CMakeFiles\cubemod.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN4Hook11InstallHookEv[__ZN4Hook11InstallHookEv]+0x89): undefined reference to `xed_decode'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [../bin/cubemod.cwmod] Error 1
make[1]: *** [CMakeFiles/cubemod.dir/all] Error 2
make: *** [all] Error 2

I'm going to start looking into these new errors, and I will appreciate any help. But I suppose the particular question posed by the title of this post can be considered 'solved'.


Solution

  • From your screenshot, you are using gcc 5.1.0.

    If you have a look at gcc standard compliance, you will see that inline variables are available from gcc 7.

    Thus, you will have to upgrade your toolchain if possible or use what is available in your version.

    Regards.