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

Failing to compile on on target but not on host (Unsupported Lua version in cross compilation) #1634

Closed
BenMcAvoy opened this issue Oct 4, 2024 · 8 comments

Comments

@BenMcAvoy
Copy link

BenMcAvoy commented Oct 4, 2024

This is enough to to cause the error, anything that includes sol causes it for me. For context, if I do not cross compile and I build for the host machine (Linux x64), everything goes well and compiles fine.

#include <sol/sol.hpp>

namespace Jenjin {
class Lua {
public:
	sol::state state;
};
}

A compilation log is visible here. The build command is visible there however I will also paste it here:

cmake -DCMAKE_BUILD_TYPE=Release \
			-DCMAKE_SYSTEM_NAME=Windows \
      -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
      -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
			-DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++ -static" \
			-DCMAKE_EXE_LINKER_FLAGS="-static" \
			-B build \
			-G Ninja

cmake --build build

I am using sol2 and lua both as submodules in a folder called vendor where vender has it's own CMakeLists.txt file:

# --- SOL2 ---
include_directories(sol2/include)
add_subdirectory(sol2)

# --- LUA ---
include_directories(lua)
file (GLOB LUA_SOURCES lua/*.c)
file (GLOB LUA_HEADERS lua/*.h)

add_library(lua STATIC ${LUA_SOURCES} ${LUA_HEADERS})

This vendor folder is then included into the root project through add_subdirectory(vendor) and then the library project is added with add_subdirectory(engine). My project is available here if it helps.

Thanks for your time! Hopefully this is just a simple misconfiguration on my end

@deadlocklogic
Copy link
Contributor

The log is saying it clearly: #error "unsupported Lua version (i.e. not Lua 5.1, 5.2, 5.3, or 5.4)"
Notice the lua version in use is 5.5, which isn't currently supported:
https://github.com/lua/lua/blob/fd0e1f530d06340f99334b07d74e5133ce073787/lua.h#L20-L22

@BenMcAvoy
Copy link
Author

BenMcAvoy commented Oct 4, 2024

Does this explain the rest of the errors? Because when I define SOL_NO_COMPAT it still has hundreds of errors which you can see below in the log, hoping this is just 5.5

Thanks so much though and also out of curiosity, why does it work on Linux then with 5.5? (Compiling to host target)

I will update once I have 5.4

@deadlocklogic
Copy link
Contributor

@BenMcAvoy

Does this explain the rest of the errors? Because when I define SOL_NO_COMPAT it still has hundreds of errors which you can see below in the log?

Once an #error directive occurs, many following errors will resolve by themselves once the error is resolved.

Thanks so much though and also out of curiosity, why does it work on Linux then with 5.5? (Compiling to host target)

Most probably sol is linking against a pre-installed supported lua package on linux, hence the compilation succeeds there.

Tried compiling your project with lua5.1 and it compiled fine.
In its current dependency you won't be able to compile because lua5.5 is not even officially released, let alone supported by sol.
Choose a stable lua version between lua 5.1-5.4 or LuaJIT, your current lua distro is a mirror of the development branch which is experimental and not released yet.
This is a clean lua5.1 repository supporting CMake used in love2d.
Feel free to close the issue if it is resolved.

@deadlocklogic
Copy link
Contributor

This is your program compiling on windows:
image

@BenMcAvoy
Copy link
Author

BenMcAvoy commented Oct 8, 2024

I have made my own megasource repo that is similar to love2ds as I did not want most of the libraries they had and I also wanted to static link. I am using their version of Lua5.1.5.

When compiling I get the following:

: && /usr/bin/c++ -g  CMakeFiles/megatest.dir/src/test.cpp.o -o megatest  libs/glfw/src/libglfw3.a  libs/libglad.a  libs/spdlog/libspdlogd.a  libs/glm/glm/libglm.a  libs/libstb.a  libs/libimgui.a  libs/lua-5.1.5/liblua51.a  /usr/lib/librt.a  -lm  -ldl && :
/usr/bin/ld: CMakeFiles/megatest.dir/src/test.cpp.o: in function `main::{lambda(std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&)#1}::operator()(std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&) const':
/home/ben/megasource/src/test.cpp:47:(.text+0x1b052): undefined reference to `lua_pcallk'

It seems that this version does not have lua_pcallk, am I doing something wrong?

@deadlocklogic
Copy link
Contributor

Your project compiles fine on my machine. lua_pcallk doesn't even have any trace in the whole repository, wonder how you are getting this error.

@BenMcAvoy
Copy link
Author

BenMcAvoy commented Oct 9, 2024

It seemed to be part of compat. I have updated to lua5.4 in my megasource repo which I meant to post here after getting it to work. I unfortunately became busy that day and forgot to update here. The megasource repo is now using lua5.4 which I have cobbled together myself and it seems to work alright. It could also be why it compiled correctly for you, that or I just have a misconfiguration on my machine. If you want me to look into the lua_pcallk error further I can do that now, if not I am happy with this library and thank you so much for helping me.

Let me know and if you're happy I will close this issue or you can if you like

@BenMcAvoy BenMcAvoy changed the title Failing to cross compile (mingw w64) (Unsupported Lua version?) Failing to compile on on target but not on host (Unsupported Lua version in cross compilation) Oct 9, 2024
@deadlocklogic
Copy link
Contributor

It is fine on my side, if you your issue is resolved, feel free to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants