问题描述
有问题的源代码的Github存储库在这里:https://github.com/arishackstv/cubemod
作为参考,这是我尝试根据自己的口味修改的Cubeworld游戏的mod。
该存储库中有一个CMakeLists.txt,我用来生成MinGW生成文件,因为创建者说该模块是使用MinGW在发布模式下构建的。这是我使用他的CMakeLists.txt进行的CMake配置:CMake Configuration
它似乎生成了makefile,没有问题,所以我尝试制作。我遇到以下错误:Errors
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;
#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)
{}
};
这个人的Github的实际编译版本确实可以正常工作,我已经尝试过了,所以奇怪的是,他的源代码遇到了编译错误。我想知道是否归结于我的构建环境未正确设置?如果有人能够成功编译该代码,我很想听听您的步骤,以了解我出了什么问题。并且如果确实是这种源代码有错误的情况,我很想听听如何解决该问题。静态内联字段不是c ++ 17的东西吗?也许就是这样吗?尽管我尝试在CMAKE_CXX_FLAGS中指定-std = C ++ 17,但这似乎没有实现。
编辑: 升级我的gcc版本的建议非常有帮助。将gcc更新到最新可用版本(9.20)后,与内联变量之类的不可用C ++功能相关的错误已修复!现在有更多的错误,但数量却少得多。这是尝试制作的新输出:
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
我将开始研究这些新错误,我们将不胜感激。但是我想,这篇文章标题所提出的特定问题可以认为是“已解决”。
解决方法
在screenshot中,您正在使用gcc 5.1.0。
如果您查看gcc standard compliance,您会发现gcc 7提供了内联变量。
因此,如果可能,您将必须升级工具链或使用版本中可用的工具。
问候。