Tencent / xLua

xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.
Other
9.32k stars 2.45k forks source link

Unity2022.3.1f1c1导出微信小游戏工程报错 #1072

Open ksgfk opened 1 year ago

ksgfk commented 1 year ago

详细报错:

Building Library\Bee\artifacts\WebGL\GameAssembly\release_WebGL_wasm\u9l0bh9rzmed.o failed with output:
In file included from Assets/Plugins/WebGL/xlua_webgl.cpp:31:
C:\Users\ksgfk\Desktop\va\WebGLPlugins\lundump.c:237:33: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
  checkliteral(S, LUA_SIGNATURE + 1, "not a");  /* 1st char already checked */
                  ~~~~~~~~~~~~~~^~~
C:\Users\ksgfk\Desktop\va\WebGLPlugins\lundump.c:237:33: note: use array indexing to silence this warning
  checkliteral(S, LUA_SIGNATURE + 1, "not a");  /* 1st char already checked */
                                ^
                  &             [  ]
In file included from Assets/Plugins/WebGL/xlua_webgl.cpp:35:
C:\Users\ksgfk\Desktop\va\WebGLPlugins\i64lib.c:409:34: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
        snprintf(temp, sizeof(temp), "%"PRIu64, n);
                                        ^

1 warning and 1 error generated.
emcc: error: '"C:/Program Files/Unity/Hub/Editor/2022.3.1f1c1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/llvm\clang++.exe" -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=8 -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL "--sysroot=C:\Program Files\Unity\Hub\Editor\2022.3.1f1c1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\cache\sysroot" -Xclang -iwithsysroot/include\compat -D__webgl__ -Wno-c++11-extensions -Wno-nonportable-include-path -ffunction-sections -fno-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -std=c++11 -Wno-#warnings -Wswitch -Wno-trigraphs -Wno-tautological-compare -Wno-invalid-offsetof -Wno-implicitly-unsigned-literal -Wno-integer-overflow -Wno-shift-negative-value -Wno-unknown-attributes -Wno-implicit-function-declaration -Wno-null-conversion -Wno-missing-declarations -Wno-unused-value -Wno-pragma-once-outside-header -fvisibility=hidden -fexceptions -fno-rtti -O3 -fno-strict-overflow -ffunction-sections -fdata-sections -fmessage-length=0 -pipe -D_GLIBCXX_USE_CXX11_ABI=0 -DBASELIB_INLINE_NAMESPACE=il2cpp_baselib -DIL2CPP_MONO_DEBUGGER_DISABLED -DRUNTIME_IL2CPP -DHAVE_BDWGC_GC -DUNITY_WEBGL=1 -DNDEBUG -I. -IC:/Users/ksgfk/Desktop/va/Library/Bee/artifacts/WebGL/il2cppOutput/cpp "-IC:/Program Files/Unity/Hub/Editor/2022.3.1f1c1/Editor/Data/il2cpp/libil2cpp/pch" "-IC:/Program Files/Unity/Hub/Editor/2022.3.1f1c1/Editor/Data/il2cpp/libil2cpp" "-IC:/Program Files/Unity/Hub/Editor/2022.3.1f1c1/Editor/Data/il2cpp/external/baselib/Include" "-IC:/Program Files/Unity/Hub/Editor/2022.3.1f1c1/Editor/Data/il2cpp/libil2cpp/os/ClassLibraryPAL/brotli/include" "-IC:/Program Files/Unity/Hub/Editor/2022.3.1f1c1/Editor/Data/il2cpp/external/baselib/Platforms/WebGL/Include" -fcolor-diagnostics -fdiagnostics-absolute-paths -c -xc++ Assets/Plugins/WebGL/xlua_webgl.cpp -o Library/Bee/artifacts/WebGL/GameAssembly/release_WebGL_wasm/u9l0bh9rzmed.o' failed (returned 1)

UnityEditor.BuildPipeline:BuildPlayer (string[],string,UnityEditor.BuildTarget,UnityEditor.BuildOptions)
WeChatWASM.WXConvertCore:Build () (at Assets/WX-WASM-SDK-V2/Editor/WXConvertCore.cs:290)
WeChatWASM.WXConvertCore:DoExport (bool) (at Assets/WX-WASM-SDK-V2/Editor/WXConvertCore.cs:97)
WeChatWASM.WXEditorWin:OnGUI () (at Assets/WX-WASM-SDK-V2/Editor/WXEditorWindow.cs:243)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

看报错提示是WebGLPlugins\i64lib.c文件409行附近不符合C++11语法

https://github.com/Tencent/xLua/blob/ad3733c7f0374e632df667430327d362507958da/WebGLPlugins/i64lib.c#L409

多加一个空格就能编译了

static int uint64_tostring(lua_State* L) {
    char temp[72];
    uint64_t n = lua_touint64(L, 1);
#if ( defined (_WIN32) ||  defined (_WIN64) ) && !defined (__MINGW32__) && !defined (__MINGW64__)
    sprintf_s(temp, sizeof(temp), "%" PRIu64, n);
#else
    snprintf(temp, sizeof(temp), "%" PRIu64, n);
#endif

    lua_pushstring(L, temp);

    return 1;
}
Gaobobo-C commented 5 months ago

找到WebGLPlugins/lundump.c 第237行,代码代码改成下面这样就可以了 checkliteral(S, &LUA_SIGNATURE[1], "not a");

报错提示是由于在 "LUA_SIGNATURE + 1" 这一表达式中进行了字符指针和整数的相加操作,这样的操作可能会导致错误,因为这不是合法的操作。这个警告意味着编译器认为您可能意图执行一个不确定的操作。解决这个问题的方法是,您可能需要明确地将 LUA_SIGNATURE 的指针与整数进行相加,然后传递给 checkliteral 函数。这可以通过使用数组索引来实现。