【发布时间】:2020-08-21 05:51:55
【问题描述】:
相关源代码的 Github 存储库在这里:https://github.com/arishackstv/cubemod
作为参考,这是游戏 Cubeworld 的一个模组,我正在尝试根据自己的喜好进行修改。
存储库有一个 CMakeLists.txt,我用它来生成 MinGW makefile,因为创建者说这个 mod 是使用 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
我将开始调查这些新的错误,如果能提供任何帮助,我将不胜感激。但我认为这篇文章的标题提出的特定问题可以被认为是“已解决”。
【问题讨论】:
-
是的,它们是 C++17 功能。也许你的编译器太旧了,不支持这个
-
gcc --version的输出是什么?没关系...我现在在屏幕截图中看到了,但其他人回答...
标签: c++ github gcc cmake mingw-w64