编译raine-0.97.4 出错:
source/sdl/console/console.cpp: In function ‘void do_lua(int, char**)’:
source/sdl/console/console.cpp:1867:28: 错误:‘LUA_OK’ was not declared in this
scope; did you mean ‘LUA_QL’?
1867 | if (ret == LUA_OK) {
| ~~~~~
| LUA_QL
source/sdl/console/console.cpp:1878:16: 错误:‘LUA_OK’ was not declared in this
scope; did you mean ‘LUA_QL’?
1878 | if (ret == LUA_OK)
| ~~~~~
| LUA_QL
make: *** [makefile:1545:linux-gnu-sdl2/object/sdl/console/console.o] 错误 1
deepseek回答是:
总结步骤:
1. 检查系统中安装的Lua版本。可以通过运行lua -v或者查看头文件中的宏定义,比如在Lua头文件中是否有定义LUA_VERSION_NUM,比如5.1是501,5.2是502,依此类推。
2. 如果Lua版本低于5.2,则修改代码中的LUA_OK为0。
3. 或者升级Lua到5.2或更高版本,确保头文件和链接库的版本一致。
4. 同时处理编译器选项的问题,移除C++编译中的-Wno-incompatible-pointer-types选项,以避免警告。
对于编译器警告,用户需要检查构建系统(如Makefile)中的CFLAGS或CXXFLAGS,确保针对C++源文件不使用仅适用于C的选项。可能需要将选项仅添加到C编译器中,而不是C++,或者使用条件判断。
不过,当前首要问题是解决LUA_OK的错误,因为这是导致编译失败的原因。警告可能暂时可以忽略,但最好后续处理。
假设用户无法升级Lua版本,那么修改代码中的LUA_OK为0即可。例如,在console.cpp中找到对应的行:
第1867行:
if (ret == LUA_OK) {
改为:
if (ret == 0) {
第1878行:
if (ret == LUA_OK)
改为:
if (ret == 0)
这样就可以在旧版Lua中编译通过。如果是新版Lua,0和LUA_OK是等价的,所以不会有问题。
看了下lua的版本,还真是5.1
lua -v
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
看了一下,系统里有多个版本的lua,
lua 5.1 lua 5.3 lua5.4
其中/usr/bin下的lua 是一个链接,指向了lua5.1,
删除掉,重新 ln 将其指向5.4
然后make clean
再make
可以看到,正确识别lua5.4了
**m700s@**aosc-3a6000 [ raine-0.97.4 ] $ make
/bin/sh: 行 1: pkg-config: 未找到命令
/bin/sh: 行 1: pkg-config: 未找到命令
/bin/sh: 行 1: pkg-config: 未找到命令
make: pkg-config: 没有那个文件或目录
make: pkg-config: 没有那个文件或目录
Building Raine, Fully optimized version with gcc for linux-gnu CPU=
dependencies : if you get an error here, install the required dev package
libpng:1.6.44
SDL:2.30.4
lua: cflags -I/usr/local/lua5.4/include libs -L/usr/local/lua5.4/lib -llua
但结果仍然是错误
cc1plus: 警告:command-line option ‘-Wno-incompatible-pointer-types’ is valid for C/ObjC but not for C++
source/sdl/console/console.cpp: In function ‘void do_lua(int, char**)’:
source/sdl/console/console.cpp:1867:28: 错误:‘LUA_OK’ was not declared in this scope; did you mean ‘LUA_QL’?
1867 | if (ret == LUA_OK) {
| ~~~~~
| LUA_QL
source/sdl/console/console.cpp:1878:16: 错误:‘LUA_OK’ was not declared in this scope; did you mean ‘LUA_QL’?
1878 | if (ret == LUA_OK)
| ~~~~~
| LUA_QL
make: *** [makefile:1547:linux-gnu-sdl2/object/sdl/console/console.o] 错误 1
按提示,改成LUA_QL
然后…………
source/sdl/console/console.cpp: In function ‘void do_lua(int, char**)’:
source/sdl/console/console.cpp:1867:28: 错误:‘LUA_QL’在此作用域中尚未声明误
1867 | if (ret == LUA_QL) {
| ~~~~~
source/sdl/console/console.cpp:1878:16: 错误:‘LUA_QL’在此作用域中尚未声明误
1878 | if (ret == LUA_QL)
| ~~~~~
make: *** [makefile:1547:linux-gnu-sdl2/object/sdl/console/console.o] 错误 1
充分说明,该错误跟lua的版本无关
还需要继续研究问题所在