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 build broken #37

Closed
Tieske opened this issue Mar 8, 2015 · 25 comments
Closed

Windows build broken #37

Tieske opened this issue Mar 8, 2015 · 25 comments

Comments

@Tieske
Copy link
Member

Tieske commented Mar 8, 2015

#21 broke the Windows build by using unix only code.

@brunoos brunoos closed this as completed Mar 12, 2015
@Tieske
Copy link
Member Author

Tieske commented Mar 13, 2015

Unfortunately the commit didn't fix it.

Luarocks output ends here;

mingw32-gcc -shared -o ssl.dll src/x509.o src/context.o src/ssl.o src/luasocket/buffer.o src/luasocket/io.o src/luasocke
t/timeout.o src/luasocket/wsocket.o -Lc:/external/lib -Lc:/external/bin -llibeay32 -lssleay32 -lws2_32 C:/Program Files
(x86)/Lua/5.1/bin/lua51.dll -lm
src/x509.o:x509.c:(.text+0xb71): undefined reference to `inet_ntop'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module ssl.dll

Press any key to close this window...

searching on this inet_ntop thing tells me that Windows doesn't have it

@brunoos
Copy link
Member

brunoos commented Mar 13, 2015

It works on VC 12.

@Tieske
Copy link
Member Author

Tieske commented Mar 13, 2015

Not on MinGW (and apparently not on any older VC versions). Here's the code; https://github.com/diegonehab/luasocket/blob/76ed24fe8ae8c728de0d7d065918a5cd74fe7303/src/inet.c#L515-537

@ignacio
Copy link
Contributor

ignacio commented Mar 13, 2015

Digging around, found this:

warmcat/libwebsockets#100 (comment)

@brunoos brunoos reopened this Apr 17, 2015
@brunoos
Copy link
Member

brunoos commented Aug 1, 2015

Could you try the last version.

Note:

/*
 * For WinXP (SP3), set the following preprocessor macros:
 *     LUASEC_INET_NTOP
 *     WINVER=0x0501
 *     _WIN32_WINNT=0x0501
 *     NTDDI_VERSION=0x05010300
 *
 * For IPv6 addresses, you need to add IPv6 Protocol to your interface.
 */

@Tieske
Copy link
Member Author

Tieske commented Aug 4, 2015

Tried it today, but failed again.

When building the rockspec:

luarocks make

mingw32-gcc -O2 -c -o src/x509.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/x509.c -DWIN32 -DNDEBUG -D_WINDOWS
 -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/include -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/context.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/context.c -DWIN32 -DNDEBUG -D_W
INDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/include -Isrc/ -Isrc/luaso
cket
mingw32-gcc -O2 -c -o src/ssl.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/ssl.c -DWIN32 -DNDEBUG -D_WINDOWS -
D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/include -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/buffer.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/buffer.c -DW
IN32 -DNDEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/include
-Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/io.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/io.c -DWIN32 -DN
DEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/include -Isrc/ -
Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/timeout.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/timeout.c -
DWIN32 -DNDEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/includ
e -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/wsocket.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/wsocket.c -
DWIN32 -DNDEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -Ic:/external/includ
e -Isrc/ -Isrc/luasocket
mingw32-gcc -shared -o ssl.dll src/x509.o src/context.o src/ssl.o src/luasocket/buffer.o src/luasocket/io.o src/luasocke
t/timeout.o src/luasocket/wsocket.o -Lc:/external/lib -Lc:/external/bin -llibeay32 -lssleay32 -lws2_32 C:/Program Files
(x86)/Lua/5.1/bin/lua51.dll -lm
src/x509.o:x509.c:(.text+0xb71): undefined reference to `inet_ntop'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module ssl.dll

Press any key to close this window...

After modifying the rockspec to define "LUASEC_INET_NTOP" it still fails;

luarocks make

mingw32-gcc -O2 -c -o src/x509.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/x509.c -DWIN32 -DNDEBUG -D_WINDOWS
 -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -Ic:/external/include -Isrc
/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/context.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/context.c -DWIN32 -DNDEBUG -D_W
INDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -Ic:/external/include
 -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/ssl.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/ssl.c -DWIN32 -DNDEBUG -D_WINDOWS -
D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -Ic:/external/include -Isrc/
-Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/buffer.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/buffer.c -DW
IN32 -DNDEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -Ic
:/external/include -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/io.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/io.c -DWIN32 -DN
DEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -Ic:/extern
al/include -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/timeout.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/timeout.c -
DWIN32 -DNDEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -
Ic:/external/include -Isrc/ -Isrc/luasocket
mingw32-gcc -O2 -c -o src/luasocket/wsocket.o -IC:/Program Files (x86)/Lua/5.1/include/lua/5.1 src/luasocket/wsocket.c -
DWIN32 -DNDEBUG -D_WINDOWS -D_USRDLL -DLSEC_EXPORTS -DBUFFER_DEBUG -DLSEC_API=__declspec(dllexport) -DLUASEC_INET_NTOP -
Ic:/external/include -Isrc/ -Isrc/luasocket
mingw32-gcc -shared -o ssl.dll src/x509.o src/context.o src/ssl.o src/luasocket/buffer.o src/luasocket/io.o src/luasocke
t/timeout.o src/luasocket/wsocket.o -Lc:/external/lib -Lc:/external/bin -llibeay32 -lssleay32 -lws2_32 C:/Program Files
(x86)/Lua/5.1/bin/lua51.dll -lm
src/x509.o:x509.c:(.text+0xbc4): undefined reference to `getnameinfo'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module ssl.dll

Press any key to close this window...

I'm travelling for a couple of weeks, so its hard to test for me right now.

@ignacio can you give this a try?

Note: I don't understand the issue. Apparently inet_ntop is defined from Vista onwards, yet on my Win7 system it continues to fail. I understand from @brunoos that it does work with the MS compilers. But I'm using MinGW, with gcc 4.8.1, on Win7 (32bit).

@brunoos
Copy link
Member

brunoos commented Aug 4, 2015

I tried on WinXP (SP3) with VS 10.
You have to set more symbols:

-DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -DNTDDI_VERSION=0x05010300 -DLUASEC_INET_NTOP

@brunoos
Copy link
Member

brunoos commented Aug 4, 2015

Again, these defines work for WinXP (SP3)
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745.aspx

The last time I tested on Win 7 with VS 12, I didn't have to define anything. I will test again.

@brunoos
Copy link
Member

brunoos commented Aug 4, 2015

gosh, I missed the last part... I will way for more feedback.

@ignacio
Copy link
Contributor

ignacio commented Aug 6, 2015

Tried today with VS2008 and WIndows 7, using
luarocks make luasec-0.5-3.rockspec OPENSSL_DIR=c:\OpenSSL-Win32\

It compiles but fails to link:

ssl.def : error LNK2001: unresolved external symbol luaopen_ssl
ssl.lib : fatal error LNK1120: 1 unresolved externals

Error: Build error: Failed compiling module ssl.dll

We need this hack in order to compile with luarocks with MS compilers.

By the way, once the problem with MS compilers is sorted out, I have a PR adding appveyor integration, so we can test using different MS compilers, plus MinGW on Windows.

@brunoos
Copy link
Member

brunoos commented Aug 28, 2015

Rockspec updated. It seems to work now.

@brunoos brunoos closed this as completed Aug 28, 2015
@ignacio
Copy link
Contributor

ignacio commented Aug 28, 2015

Sadly, it still won't build with LuaRocks and a MS compiler.

@brunoos
Copy link
Member

brunoos commented Aug 28, 2015

What is the error?

If you have:

...
link -dll -def:ssl.def -out:ssl.dll C:/devel/lua5.1/lib/lua5.1.lib src/x509.obj
src/context.obj src/ssl.obj src/luasocket/buffer.obj src/luasocket/io.obj src/lu
asocket/timeout.obj src/luasocket/wsocket.obj -libpath:c:\devel\openssl/lib -lib
path:c:\devel\openssl/bin libeay32.lib ssleay32.lib ws2_32.lib
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

ssl.def : error LNK2001: unresolved external symbol luaopen_ssl
ssl.lib : fatal error LNK1120: 1 unresolved externals

Error: Build error: Failed compiling module ssl.dll

It is a LuaRocks issue.

@ignacio
Copy link
Contributor

ignacio commented Aug 29, 2015

Yes, that is the error. Could we get this fix added in the meantime?
ignacio@b315a19

I know this is a LuaRocks thing, but it'd really nice to get luasec to build with ms compilers.

@brunoos
Copy link
Member

brunoos commented Aug 29, 2015

sorry, I will not add this patch to deal with this LuaRocks issue.

I realized that luasec has 6 variations on Windows:

  • WinXP: VS, LuaRocks VS, LuaRocks MinGW (no inet_pton)
  • non-WinXP: VS, LuaRocks VS, LuaRocks MinGW (with inet_pton)

Besides, we have linux, osx and *bsd.

I will not add workarounds to deal with build tools in the code if it is not luasec fault.

This is a patch to luarocks that add an "exports" field, which informs the modules that must be exported from DLL.

--- builtin.old.lua 2015-08-29 08:18:07.000000000 -0300
+++ builtin.lua 2015-08-29 08:26:28.000000000 -0300
@@ -106,7 +106,7 @@
          add_flags(extras, "-I%s", incdirs)
          return execute(variables.CC.." "..variables.CFLAGS, "-c", "-Fo"..object, "-I"..variables.LUA_INCDIR, source, unpack(extras))
       end
-      compile_library = function(library, objects, libraries, libdirs, name)
+      compile_library = function(library, objects, libraries, libdirs, name, exports)
          local extras = { unpack(objects) }
          add_flags(extras, "-libpath:%s", libdirs)
          add_flags(extras, "%s.lib", libraries)
@@ -114,7 +114,13 @@
          local deffile = basename .. ".def"
          local def = io.open(dir.path(fs.current_dir(), deffile), "w+")
          def:write("EXPORTS\n")
-         def:write("luaopen_"..name:gsub("%.", "_").."\n")
+         if exports then
+            for i, module in ipairs(exports) do
+               def:write("luaopen_"..module:gsub("%.", "_").."\n")
+            end
+         else
+            def:write("luaopen_"..name:gsub("%.", "_").."\n")
+         end
          def:close()
          local ok = execute(variables.LD, "-dll", "-def:"..deffile, "-out:"..library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), unpack(extras))
          local basedir = ""
@@ -244,7 +250,7 @@
             if not ok then return nil, err end
          end
          built_modules[module_name] = dir.path(libdir, module_name)
-         ok = compile_library(module_name, objects, info.libraries, info.libdirs, name)
+         ok = compile_library(module_name, objects, info.libraries, info.libdirs, name, info.exports)
          if not ok then
             return nil, "Failed compiling module "..module_name
          end

Using with rockspec:

      windows = {
         install = {
            lib = {
               "ssl.dll"
            },
            lua = {
               "src/ssl.lua", ['ssl.https'] = "src/https.lua"
            }
         },
         modules = {
            ssl = {
               defines = {
                  "WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)",
                  "LUASEC_INET_NTOP", "WINVER=0x0501", "_WIN32_WINNT=0x0501", "NTDDI_VERSION=0x05010300"
               },
               libdirs = {
                  "$(OPENSSL_LIBDIR)",
                  "$(OPENSSL_BINDIR)",
               },
               libraries = {
                  "libeay32", "ssleay32", "ws2_32"
               },
               incdirs = {
                  "$(OPENSSL_INCDIR)", "src/", "src/luasocket"
               },
               sources = {
                  "src/x509.c", "src/context.c", "src/ssl.c",
                  "src/luasocket/buffer.c", "src/luasocket/io.c",
                  "src/luasocket/timeout.c", "src/luasocket/wsocket.c"
               },
               exports = { "ssl.core", "ssl.context", "ssl.x509" }
            }
         }
      }

@ignacio
Copy link
Contributor

ignacio commented Aug 29, 2015

Fair enough.
Since this is an issue with the build tool (luarocks), would you consider supporting LR + Visual Studio by means of a patch in the rockspec?
I can submit a PR if you're willing to approve it.

Thanks for the patch above. Would you mind submitting it to LuaRocks? There is an issue here were this matter has been discussed.

@ignacio
Copy link
Contributor

ignacio commented Aug 30, 2015

Ah, also, while in the process of setting up a continuous integration server (appveyor) I found that the mingw build is failing with this error:

In file included from c:\mingw\include\_mingw.h:35:0,
                 from c:\mingw\include\string.h:29,
                 from src/x509.c:9:
c:\mingw\include\sdkddkver.h:137:8: error: #error The _WIN32_WINNT value does not match NTDDI_VERSION
 #      error The _WIN32_WINNT value does not match NTDDI_VERSION
        ^

It seems that it is using mingw 4.8.2 (http://www.appveyor.com/docs/installed-software#mingw-msys-cygwin).

If I edit the rockspec and only add this defines:

defines = {
  "WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)",
  "LUASEC_INET_NTOP", "_WIN32_WINNT=0x0501"
}

the it compiles ok. What would be the minimum mingw version that is supported?

@ignacio
Copy link
Contributor

ignacio commented Jan 21, 2016

Hi. Any thoughts on this? I'm talking about the possibility of having a patch in the rockspec to support MS compilers. Would you accept a PR for that?

@brunoos
Copy link
Member

brunoos commented Jan 25, 2016

I can add the "defines" without problem.
Will Luarocks support it?

@ignacio
Copy link
Contributor

ignacio commented Jan 25, 2016

About the "defines", I'll need @Tieske thoughts on this since he is more knowledgeable on all things mingw.

I was also talking about adding a patch in the rockspec, to let luasec compile with MS compilers. Could you add that too to the rockspec if I sent you the required changes?

@brunoos
Copy link
Member

brunoos commented Jan 27, 2016

Yes, I add.

@ignacio
Copy link
Contributor

ignacio commented Jan 31, 2016

Hi @brunoos
I've just sent a PR that adds the patch to fix the linking issue when installing with LuaRocks and using Microsoft compilers.

I did not change anything to the defines because mingw is not my area of expertise and I'm afraid I can break something inadvertently.

@Tieske
Copy link
Member Author

Tieske commented Feb 17, 2016

I just tried luarocks make from the repository root, it picked the 0.6alpha rockspec and build it properly (using the MinGW toolchain).

seems to work just fine

@ignacio
Copy link
Contributor

ignacio commented Feb 17, 2016

Great to hear that, @Tieske
Which version is your mingw install?

@Tieske
Copy link
Member Author

Tieske commented Feb 21, 2016

frankly I don't have a clue... gcc reports 4.8.1 (it's 32 bit)

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

No branches or pull requests

3 participants