Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Minetest 5.7.0 on MacOS: error: use of undeclared identifier 'luaopen_bit' #13548

Closed
giangduong opened this issue May 31, 2023 · 8 comments
Labels
@ Build CMake, build scripts, official builds, compiler and linker errors macOS Possible close Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible

Comments

@giangduong
Copy link

Minetest version
5.7.0
OS / Hardware

Operating system: MacOS
CPU: Intel

GPU model:
OpenGL version: 2.1

Summary

I used to build this version successfully in my MacBook. But today, i got a strange error.

image

I also take a look at minetest/lib/lua/src/lualib.h. There is no definition of luaopen_bit or LUA_BITLIBNAME and LUA_JITLIBNAME

Steps to reproduce

git clone --depth 1 https://github.com/minetest/minetest.git
cd minetest

git clone --depth 1 https://github.com/minetest/irrlicht.git lib/irrlichtmt

mkdir build
cd build

cmake ..
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.7
-DBUILD_SERVER=FALSE
-DBUILD_CLIENT=TRUE
-DENABLE_GETTEXT=TRUE
-DENABLE_FREETYPE=FALSE
-DENABLE_GETTEXT=TRUE
-DCMAKE_FIND_FRAMEWORK=LAST
-DCMAKE_INSTALL_PREFIX=../build/macos/
-DRUN_IN_PLACE=FALSE

make package -j$(sysctl -n hw.logicalcpu)

@giangduong giangduong added the Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible label May 31, 2023
@sfan5
Copy link
Member

sfan5 commented May 31, 2023

Do you have the output from when you run the "cmake" command?
It looks like the build got confused whether you have LuaJIT or not.

@giangduong
Copy link
Author

giangduong commented May 31, 2023

Yes, here you are.

image image

@Zughy Zughy added @ Build CMake, build scripts, official builds, compiler and linker errors macOS labels May 31, 2023
@SmallJoker
Copy link
Member

Your Minetest build uses LuaJIT 5.1 (any version from 2017-now), however it seems to be new enough to have luaopen_string_buffer:

minetest/src/CMakeLists.txt

Lines 701 to 716 in 7221de6

if(USE_LUAJIT)
set(CMAKE_REQUIRED_LIBRARIES ${LUA_LIBRARY})
# LuaJIT provides exactly zero ways to determine how recent it is (the version
# is unchanged since 2017), however it happens that string buffers were added
# after the changes which we care about so that works as an indicator.
# (https://github.com/LuaJIT/LuaJIT/commit/4c6b669 March 2021)
unset(HAVE_RECENT_LJ CACHE)
check_symbol_exists(luaopen_string_buffer "lualib.h" HAVE_RECENT_LJ)
if(NOT HAVE_RECENT_LJ)
string(CONCAT explanation_msg
"You are using a relatively old version of LuaJIT. We recommend "
"running a recent version (from git) as older ones are known not "
"to build/work correctly in all cases.\n"
"THIS APPLIES ESPECIALLY ON macOS OR Linux/aarch64!")
message(WARNING ${explanation_msg})
endif()

But it appears that your LuaJIT installation was not compiled with the BitOp library (expected to be included with luajit.h:

#include "lualib.h"
#if USE_LUAJIT
#include "luajit.h"
#else
#include "bit.h"
#endif

As a workaround you could either (recommended) try to figure out which LuaJIT build comes with BitOp or (less recommended) try to make use of the bundled library: (also requires you to include the file like the part shown in the code above)

minetest/CMakeLists.txt

Lines 306 to 308 in 8cd1296

if(NOT USE_LUAJIT)
add_subdirectory(lib/bitop)
endif()

@sfan5
Copy link
Member

sfan5 commented May 31, 2023

It's also failing to find luaopen_jit so it's not actually LuaJIT. The extra LUA_INCLUDE_DIR probably confuses our build script (try removing that).

As an aside sibce you are building 5.7.0 then IrrlichtMt 1.9.0.10 should be required, yet your output shows 1.9.0.8. Weird.

@giangduong
Copy link
Author

It's also failing to find luaopen_jit so it's not actually LuaJIT. The extra LUA_INCLUDE_DIR probably confuses our build script (try removing that).

As an aside sibce you are building 5.7.0 then IrrlichtMt 1.9.0.10 should be required, yet your output shows 1.9.0.8. Weird.

I did try a few different ways.

I tried to install the latest luajit 2.1. I can see that the lualib.h has definitions of luaopen_jit, LUA_JITLIBNAME, and LUA_BITLIBNAME. In order to use luajit 2.1, i'll need to add extra 'LUA_INCLUDE_DIR'.

$ cmake .. \

-DCMAKE_OSX_DEPLOYMENT_TARGET=11.7 \
-DBUILD_SERVER=FALSE \
-DBUILD_CLIENT=TRUE \
-DENABLE_GETTEXT=TRUE \
-DENABLE_FREETYPE=FALSE \
-DENABLE_GETTEXT=TRUE \
-DENABLE_LUAJIT=TRUE \

-DLUA_INCLUDE_DIR=/usr/local/include/luajit-2.1
-DCMAKE_FIND_FRAMEWORK=LAST
-DCMAKE_INSTALL_PREFIX=../build/macos/
-DRUN_IN_PLACE=FALSE

I think the issue is fixed. But i got another issue.

image

@giangduong
Copy link
Author

Your Minetest build uses LuaJIT 5.1 (any version from 2017-now), however it seems to be new enough to have luaopen_string_buffer:

minetest/src/CMakeLists.txt

Lines 701 to 716 in 7221de6

if(USE_LUAJIT)
set(CMAKE_REQUIRED_LIBRARIES ${LUA_LIBRARY})
# LuaJIT provides exactly zero ways to determine how recent it is (the version
# is unchanged since 2017), however it happens that string buffers were added
# after the changes which we care about so that works as an indicator.
# (https://github.com/LuaJIT/LuaJIT/commit/4c6b669 March 2021)
unset(HAVE_RECENT_LJ CACHE)
check_symbol_exists(luaopen_string_buffer "lualib.h" HAVE_RECENT_LJ)
if(NOT HAVE_RECENT_LJ)
string(CONCAT explanation_msg
"You are using a relatively old version of LuaJIT. We recommend "
"running a recent version (from git) as older ones are known not "
"to build/work correctly in all cases.\n"
"THIS APPLIES ESPECIALLY ON macOS OR Linux/aarch64!")
message(WARNING ${explanation_msg})
endif()

But it appears that your LuaJIT installation was not compiled with the BitOp library (expected to be included with luajit.h:

#include "lualib.h"
#if USE_LUAJIT
#include "luajit.h"
#else
#include "bit.h"
#endif

As a workaround you could either (recommended) try to figure out which LuaJIT build comes with BitOp or (less recommended) try to make use of the bundled library: (also requires you to include the file like the part shown in the code above)

minetest/CMakeLists.txt

Lines 306 to 308 in 8cd1296

if(NOT USE_LUAJIT)
add_subdirectory(lib/bitop)
endif()

I replaced the minetest/src/CMakeLists.txt with the one you mentioned above.

When running cmake, i got this error.

image

@giangduong
Copy link
Author

The strange thing is i can build successfully if i get the latest code from github which is 5.8.0. On the same Mac and follow the same build steps.

@sfan5
Copy link
Member

sfan5 commented Jun 1, 2023

It looks like your source code checkout is just broken/corrupted. Try deleting it and start over.
Note that you can check out the stable version using -b stable-0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Build CMake, build scripts, official builds, compiler and linker errors macOS Possible close Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible
Projects
None yet
Development

No branches or pull requests

4 participants