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

windows module lua5.1 Compilation fails #31

Closed
july0426 opened this issue Jan 27, 2021 · 7 comments
Closed

windows module lua5.1 Compilation fails #31

july0426 opened this issue Jan 27, 2021 · 7 comments

Comments

@july0426
Copy link

MSVC with LUA_INC / LUA_LIB / LUA_LIB_NAME environment variables. Windows 10 ,mlua 5.0.1 I set up,but faild. Can you give a more detailed example or configuration

@khvzak
Copy link
Member

khvzak commented Jan 27, 2021

A first example is from github actions where I test Lua modules on Windows:
https://github.com/khvzak/mlua/blob/master/.github/workflows/main.yml#L186

A second example is using Windows + MSVC

  1. Download binary Lua dll & lib (I used the luabinaries project, this file)
  2. Unzip to lua51 folder
  3. Go to mlua/examples/module
  4. From git shell
$ LUA_INC=$HOME/Downloads/lua51/include LUA_LIB=$HOME/Downloads/lua51 LUA_LIB_NAME=lua5.1 cargo build --features lua51

Build ok, we got mlua/target/debug/rust_module.dll

For testing:

  1. Go to mlua/target/debug
  2. Run
$ lua5.1 -e 'print(require("rust_module").sum(2,3))'
5
$ lua5.1 -e 'print(require("rust_module").used_memory())'
35441

Windows 10, Latest MSVC Community, Git, Rust 1.49.0

@july0426
Copy link
Author

july0426 commented Jan 28, 2021

Thank you very much for your reply. I succeeded !!!
The reason for the failure is that Lua's lib was downloaded incorrectly. I succeeded in both Lua5.1 and Lua5.4

@july0426
Copy link
Author

Now I have a new problem. The compiled DLL is required and executed correctly by Lua54.exe, but not by LuaQuire in Rust. Any solution,
like this
`use mlua::prelude::*;

fn main() -> LuaResult<()> {
let lua = unsafe {Lua::new()};
lua.load(r#"print(require("my_module").sum(2,3))"#).exec()?;

Ok(())

}`

@khvzak
Copy link
Member

khvzak commented Jan 28, 2021

The line
let lua = unsafe {Lua::new()};
should be replaced with
let lua = unsafe { Lua::unsafe_new() };
to allow loading C modules

@july0426
Copy link
Author

DLL is compiled in features=['lua54','module'] mode
The rust project is compliated with eatures=['lua54','vendored'] mode

@july0426
Copy link
Author

july0426 commented Jan 28, 2021

Lua library does not load properly without lua54. DLL, but I cannot find a way to link lua54. DLL to the library

@khvzak khvzak closed this as completed Feb 3, 2024
@Queen-Studio
Copy link

A first example is from github actions where I test Lua modules on Windows: https://github.com/khvzak/mlua/blob/master/.github/workflows/main.yml#L186

A second example is using Windows + MSVC

  1. Download binary Lua dll & lib (I used the luabinaries project, this file)
  2. Unzip to lua51 folder
  3. Go to mlua/examples/module
  4. From git shell
$ LUA_INC=$HOME/Downloads/lua51/include LUA_LIB=$HOME/Downloads/lua51 LUA_LIB_NAME=lua5.1 cargo build --features lua51

Build ok, we got mlua/target/debug/rust_module.dll

For testing:

  1. Go to mlua/target/debug
  2. Run
$ lua5.1 -e 'print(require("rust_module").sum(2,3))'
5
$ lua5.1 -e 'print(require("rust_module").used_memory())'
35441

Windows 10, Latest MSVC Community, Git, Rust 1.49.0

Excuse me, sir!
My computer is Windows 10 64 bit, installed with 64-bit Rust 1.82.0, and Lua is 32-bit. How should I compile it into a 32-bit DLL?
I have did the following settings:

  1. Set the target platform in the bottom right corner of RustRover to "i686-pc-windows-msvc".
  2. Modify the config file content in ".cargo" to:
    [target.i686-pc-windows-msvc]
    rustflags = [
    "-C", "link-arg=-undefined",
    "-C", "link-arg=dynamic_lookup",
    ]
  3. Using "cd F:\rust_lua_src\mlua-0.10.0\examples\module" to switch to the module directory in RustRover's command line.
  4. Enter git-bash.exe in the command line, and then show the "MINGW64:/f/rust_1ua_strc/mlua-0.10.0/sample/module" window.
  5. Using "LUA_INC=F:/rust_1ua_strc/lua51-x86/include LUA_LIB=F:/rust_1ua_strc/lua51-x86 LUA_LIBNAME=lua5.1 cargo build -- features lua51" to compile in the window.
    I got an error:
    F: \ rust_1ua_Src \ lua51-x86 \ lua5.1.lib: warning LNK4272: The library computer type "x86" conflicts with the target computer type "x64".
    So,
    I have set the compilation platform to x86, but there are still errors and I don't know where the problem lies.
    If possible, can you answer for me?
    thank you.

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

3 participants