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 support #53

Open
moteus opened this issue Aug 24, 2016 · 4 comments
Open

Windows support #53

moteus opened this issue Aug 24, 2016 · 4 comments

Comments

@moteus
Copy link

moteus commented Aug 24, 2016

Now problem with Windows that there no config.h files. And it require install mingw to be able use configure.
I add this config.h file to my project

/* confdefs.h */
#define PACKAGE_NAME "alien"
#define PACKAGE_TARNAME "alien"
#define PACKAGE_VERSION "0.7.1"
#define PACKAGE_STRING "alien 0.7.1"
#define PACKAGE_BUGREPORT "http://mascarenhas.github.com/alien"
#define PACKAGE_URL ""
#define PACKAGE "alien"
#define VERSION "0.7.1"
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STDINT_H 1
#define LT_OBJDIR ".libs/"
#define STDC_HEADERS 1
#define HAVE_FFI_H 1

And I can compile alien with MSVC (with my fixes #49 , #50 , #51 ) and all tests pass.
Also I add rockspec file to be able install it on Windows.

build = {
  type = "command",
  build_command = "./bootstrap && ./configure LUA=$(LUA) CPPFLAGS='-I$(LUA_INCDIR) -I$(FFI_INCDIR)' LDFLAGS=-L$(FFI_LIBDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --datadir=$(LUADIR) && make clean && make",
  install_command = "make install",
  copy_directories = {},

  platforms = { windows = {
    type = "builtin",
    copy_directories = {},
    modules = {
      alien_c = {
        sources = {"src/alien.c"},
        defines = {"FFI_BUILDING", "WINDOWS"},
        libraries = {"ffi"},
        incdirs = {"$(FFI_INCDIR)"},
        libdirs = {"$(FFI_LIBDIR)"}
      },
      alien = 'src/alien.lua',
    }
  }}
}
>luarocks install https://raw.githubusercontent.com/moteus/alien/master/rockspecs/alien-scm-0.rockspec
Cloning into 'alien'...
remote: Counting objects: 2559, done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 2559 (delta 17), reused 0 (delta 0), pack-reused 2527
Receiving objects: 100% (2559/2559), 2.58 MiB | 119.00 KiB/s, done.
Resolving deltas: 100% (1498/1498), done.
Checking connectivity... done.
cl /nologo /MD /O2 -c -Fosrc/alien.obj -Ic:/Lua/5.1/include/ src/alien.c -DFFI_BUILDING -DWINDOWS -Ic:/lua/external/include
alien.c
link -dll -def:alien_c.def -out:alien_c.dll c:/Lua/5.1/lib/lua51.lib src/alien.obj -libpath:c:/lua/external/lib ffi.lib
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library alien_c.lib and object alien_c.exp
alien scm-0 is now installed in c:\Lua\5.1\systree (license: MIT/X11)

Also I add travis file to run tests on Travis CI service.

@aryajur
Copy link

aryajur commented Apr 25, 2018

I tried this and compiled the dll file but somehow not able to load it in windows. I am using Lua 5.3. When I require alien then I get the error saying:

error loading module 'alien_c' from file '.\alien_c.dll':
The specified network name is no longer available

I tried changing the module name in the alien.c file and tried a couple of variations but no success. I thought it might be getting confused by the submodule syntax but when I changed it to alienc.dll with the function called luaopen_alienc, I was still having the same problem.
Any hints or help would be useful.

@aryajur
Copy link

aryajur commented Apr 25, 2018

The problem was that libffi.dll was not in the path so it was not able to find it. Once I put that in there it worked.

@robertlzj
Copy link

The problem was that libffi.dll was not in the path so it was not able to find it. Once I put that in there it worked.

Next time could use lucasg/Dependencies: A rewrite of the old legacy software "depends.exe" in C# for Windows devs to troubleshoot dll load dependencies issues. to check dll libs dependences.

@roman-orekhov
Copy link

To avoid problems like @robertlzj had in #56 (comment) on Windows 64bit one should replace these strings

static const ffi_abi ffi_abis[] = { FFI_DEFAULT_ABI, FFI_SYSV, FFI_STDCALL };
static const char *const ffi_abi_names[] = { "default", "cdecl", "stdcall", NULL };

with a list of ABIs you want and your libffi provides. As seen here, X86_WIN64 only provides FFI_WIN64 and FFI_GNUW64 values (+defaults). Or you can remove the feature altogether, remove two tests (search for abi here) and set abi to default here

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

4 participants