About a week ago, I built libnettle 2.4 on MS-Windows using the MinGW tools. While doing that, I found a few problems; this message reports them.
For the record, I configured using " --disable-openssl --enable-shared". This was suggested by the GnuTLS README file; as I needed libnettle to build GnuTLS, I followed that advice.
Problem #1: Compiler warnings while compiling cbc.c:
cbc.c: In function `nettle_cbc_decrypt': cbc.c:101: warning: implicit declaration of function `alloca' cbc.c:101: warning: nested extern declaration of `alloca'
I fixed this by adding this to config.h.in:
/* Needed for alloca on MinGW */ # if HAVE_MALLOC_H # include <malloc.h> # endif
malloc.h in MinGW defines alloca to the GCC builtin; if the above is absent, the compiler falls back on "char *alloca()" which causes the warnings.
Problem #2: "make install" incorrectly copies the DLL files into lib/*.dll.a. *.dll.a are the Windows import libraries for using during the link stage; the *.dll dynamic libraries themselves should be copied into the $(bindir) directory.
My solution was to add commands to corresponding recipes that cater to Windows, where *_SONAME variables are empty:
install-shared-hogweed: $(LIBHOGWEED_FORLINK) $(MKDIR_P) $(DESTDIR)$(libdir) $(MKDIR_P) $(DESTDIR)$(bindir) [ -z "$(LIBHOGWEED_SONAME)" ] \ && $(INSTALL_DATA) $(LIBHOGWEED_FORLINK) $(DESTDIR)$(bindir) [ -z "$(LIBHOGWEED_SONAME)" ] \ && $(INSTALL_DATA) $(LIBHOGWEED_FILE) $(DESTDIR)$(libdir) [ -z "$(LIBHOGWEED_SONAME)" ] \ || $(INSTALL_DATA) $(LIBHOGWEED_FORLINK) $(DESTDIR)$(libdir)/$(LIBHOGWEED_FILE) [ -z "$(LIBHOGWEED_SONAME)" ] \ || (cd $(DESTDIR)$(libdir) \ && $(LN_S) $(LIBHOGWEED_FILE) $(LIBHOGWEED_SONAME) \ && $(LN_S) $(LIBHOGWEED_FILE) $(LIBHOGWEED_FORLINK))
Problem #3: Tests crash because they don't find libhogweed-2-1.dll. This is because Makefile uses "ln -sf" to create .lib/*.dll.
Solution: add LN_S variable to Makefile.in, and then re-run the build with "make LN_S='cp -prf'. Also, add this command to the recipes that build shared libraries:
[ -z "$(LIBNETTLE_SONAME)" ] && (cd .lib \ && $(LN_S) ../$(LIBNETTLE_FORLINK) $(LIBNETTLE_FORLINK))
so that the DLLs are copied to .lib/ under the same name.
Problem #4: Tests in `examples' crash, cannot find libhogweed-2-1.
Solution: add ../.lib to PATH, like testsuite/Makefile.in does.
Problem #5: testsuite/pkcs1-conv fails due to CRLF vs LF issue in compared files (MinGW programs produce text files where each line ends in CRLF, while the test expects the Unix-style LF-only end-of-line format).
Solution: add --strip-trailing-cr switch to diff.
Problem #6: testsuite/sexp-conv fails due to CRLF vs LF issue in compared files.
Solution: use "diff --strip-trailing-cr" instead of "cmp".
Problem #7: examples/setup-env fails because it tries to read from rsa-decrypt, which doesn't exist. It should instead read from rsa-decrypt.exe.
Solution: fix setup-env to check which program file is actually present and read from that.
A similar problem is in examples/rsa-encrypt-test.
Problem #8: examples/rsa-encrypt-test fails because rsa-encrypt.c and rsa-decrypt.c read/write binary data from stdin to stdout, but do not set these streams to binary mode.
To solve this, I added code to the test programs to use binary mode. Let me know if you want me to submit patches for that.
Last, but not least: thanks for developing and maintaining libnettle!
Hi Eli,
On Sat, 7 Jan 2012, Eli Zaretskii wrote:
About a week ago, I built libnettle 2.4 on MS-Windows using the MinGW tools. While doing that, I found a few problems; this message reports them.
Many of these issues have been fixed in the latest version in CVS - please retry with that version and see which ones of them still apply.
Of these, we've at least worked on problem #2, #5, #6, #7, #8, and improved the assembler code to work on windows. It's been mostly tested when building under linux though (and running tests through wine), so there might perhaps still be some issues when running under real windows.
// Martin
Eli Zaretskii eliz@gnu.org writes:
About a week ago, I built libnettle 2.4 on MS-Windows using the MinGW tools. While doing that, I found a few problems; this message reports them.
Thanks for testing. As Martin wrote, there has been some progress on windows support since the release. It would be great if you could test the cvs version (sorry it's a little cumbersome; you need to check out the lsh tree and follow the instructions on http://www.lysator.liu.se/~nisse/nettle/).
Problem #1: Compiler warnings while compiling cbc.c:
cbc.c: In function `nettle_cbc_decrypt': cbc.c:101: warning: implicit declaration of function `alloca' cbc.c:101: warning: nested extern declaration of `alloca'
Not fixed, as far as I know. I don't see this warning when cross compiling, so I guess this reflects a real difference in native builds.
Problem #2: "make install" incorrectly copies the DLL files into lib/*.dll.a. *.dll.a are the Windows import libraries for using during the link stage; the *.dll dynamic libraries themselves should be copied into the $(bindir) directory.
Should be fixed, thanks to Martin.
Problem #3: Tests crash because they don't find libhogweed-2-1.dll. This is because Makefile uses "ln -sf" to create .lib/*.dll.
Not fixed. Using an LN_S make variable makes sense to me, but there should also be a corresponding configure check (hopefully there's some standard autoconf test?). Patch appreciated.
Problem #4: Tests in `examples' crash, cannot find libhogweed-2-1.
Solution: add ../.lib to PATH, like testsuite/Makefile.in does.
Seems right. Checked in now.
Problem #5: testsuite/pkcs1-conv fails due to CRLF vs LF issue in compared files (MinGW programs produce text files where each line ends in CRLF, while the test expects the Unix-style LF-only end-of-line format).
Solution: add --strip-trailing-cr switch to diff.
Fixed, I think (and also #6). Files are massaged with tr as needed, since that's more portable than relying on GNU diff.
Problem #7: examples/setup-env fails because it tries to read from rsa-decrypt, which doesn't exist. It should instead read from rsa-decrypt.exe.
Solution: fix setup-env to check which program file is actually present and read from that.
Fixed, by passing $EXEEXT in the environment and using it in setup-env and also in other test scripts.
Problem #8: examples/rsa-encrypt-test fails because rsa-encrypt.c and rsa-decrypt.c read/write binary data from stdin to stdout, but do not set these streams to binary mode.
To solve this, I added code to the test programs to use binary mode. Let me know if you want me to submit patches for that.
These files now do
#ifdef WIN32 setmode(0, O_BINARY); setmode(1, O_BINARY); #endif
Do you think this is a correct solution?
Regards, /Niels
From: nisse@lysator.liu.se (Niels Möller) Cc: nettle-bugs@lists.lysator.liu.se Date: Sat, 07 Jan 2012 22:08:30 +0100
Thanks for testing. As Martin wrote, there has been some progress on windows support since the release. It would be great if you could test the cvs version (sorry it's a little cumbersome; you need to check out the lsh tree and follow the instructions on http://www.lysator.liu.se/~nisse/nettle/).
I will try that when I have time, if a new release is too far to wait until then.
Doesn't building from CVS require additional tools, like Autoconf and Automake?
Problem #3: Tests crash because they don't find libhogweed-2-1.dll. This is because Makefile uses "ln -sf" to create .lib/*.dll.
Not fixed. Using an LN_S make variable makes sense to me, but there should also be a corresponding configure check (hopefully there's some standard autoconf test?). Patch appreciated.
LN_S is a standard autoconf thing, so it should be easy. Sorry, I don't know about autoconf enough to send a patch. However, by looking at random configure scripts, I found that having this in configure.ac:
AC_PROG_LN_S
is probably all you need.
Problem #8: examples/rsa-encrypt-test fails because rsa-encrypt.c and rsa-decrypt.c read/write binary data from stdin to stdout, but do not set these streams to binary mode.
To solve this, I added code to the test programs to use binary mode. Let me know if you want me to submit patches for that.
These files now do
#ifdef WIN32 setmode(0, O_BINARY); setmode(1, O_BINARY); #endif
Do you think this is a correct solution?
Yes, except that I would use _setmode, as that will also work for Windows compilers other than MinGW.
Thanks.
Eli Zaretskii eliz@gnu.org writes:
Doesn't building from CVS require additional tools, like Autoconf and Automake?
Autoconf is needed. So if you don't have autoconf on the windows box, what you'd need to do is check it out to a unix/gnu/linux-system, run the .bootstrap scripts (as per the instructions), and do a ./configure && make && make dist in the nettle directory. And then copy the resulting .tar.gz to the windows machine. So it's not very convenient.
When the lsh xenofarm is up and running, you can also cheat and get a recent lsh snapshot from http://www.lysator.liu.se/xenofarm/lsh/builds/latest. At the moment, the most recent snapshot there is from October, but if things goes well a current one should be prepared within an hour or so.
I'm not sure when I'll get around to making a new release.
AC_PROG_LN_S
is probably all you need.
[...]
Yes, except that I would use _setmode, as that will also work for Windows compilers other than MinGW.
Noted. I'll see what I can do.
Regards, /Niels
Eli Zaretskii eliz@gnu.org writes:
I found that having this in configure.ac:
AC_PROG_LN_S
is probably all you need.
I have added this now.
Yes, except that I would use _setmode, as that will also work for Windows compilers other than MinGW.
And this.
I also found out that dlls apperantly weren't linked into the .lib directory, so I tried to fix that as well. This directory is added to LD_LIBRARY_PATH (for ELF systems) and PATH (for windows), when running the testsuite.
Unfortunately, I couldn't figure out how to get wine to add the .lib directory to the initial PATH. So for now, as a workaround, I create symlinks also in the testsuite and examples subdirectories in the build tree, when cross compiling for windows. With that change,
./configure '--host=i586-mingw32msvc' '--enable-shared' make make check
works for me.
I just put up a prerelease at http://www.lysator.liu.se/~nisse/archive/nettle-2.5-pre.tar.gz (and .sig), any testing (in particular on windows) is appreciated.
Regards, /Niels
nisse@lysator.liu.se (Niels Möller) writes:
I just put up a prerelease at http://www.lysator.liu.se/~nisse/archive/nettle-2.5-pre.tar.gz (and .sig), any testing (in particular on windows) is appreciated.
With MinGW-64 I got the following error when building:
make[1]: Entering directory `/home/jas/src/nettle-2.5-pre/testsuite' i686-w64-mingw32-g++ -g -O2 -L.. cxx-test.o testutils.o -lnettle -o cxx-test.exe /home/jas/src/mingw-w64-32/build/root/lib/gcc/i686-w64-mingw32/4.5.1/../../../../i686-w64-mingw32/bin/ld: cannot find -lgcc_s /home/jas/src/mingw-w64-32/build/root/lib/gcc/i686-w64-mingw32/4.5.1/../../../../i686-w64-mingw32/bin/ld: cannot find -lgcc_s collect2: ld returnerade avslutningsstatus 1 make[1]: *** [cxx-test.exe] Fel 1
It may be that my MinGW-64 g++ installation is not working properly. When I passed 'CXX=false' to ./configure it built without errors.
Most self-checks works, except if fails at the end:
PASS: sexp-conv SKIP: pkcs1-conv PASS: symbols =================== All 36 tests passed =================== rm: argument saknas Försök med "rm --help" för mer information. FAIL: ./teardown-env make[1]: *** [check] Fel 1
The call to find in teardown-env turns out empty. This seems to be the case when I build with --enable-shared as well -- then there is only one hit (./.lib/libnettle-4-3.dll), but it is not under testsuite/. Should there be more *.dll files?
/Simon
Simon Josefsson simon@josefsson.org writes:
With MinGW-64 I got the following error when building:
For clarity: Is this MinGW-64 *natively* on a windows machine, or a cross compiler?
make[1]: Entering directory `/home/jas/src/nettle-2.5-pre/testsuite' i686-w64-mingw32-g++ -g -O2 -L.. cxx-test.o testutils.o -lnettle -o cxx-test.exe /home/jas/src/mingw-w64-32/build/root/lib/gcc/i686-w64-mingw32/4.5.1/../../../../i686-w64-mingw32/bin/ld: cannot find -lgcc_s make[1]: *** [cxx-test.exe] Fel 1
It may be that my MinGW-64 g++ installation is not working properly.
Seems likely; I can't see any reason why the compilation command line should give that error.
FAIL: ./teardown-env make[1]: *** [check] Fel 1
The call to find in teardown-env turns out empty.
Ooops. I should replace that backtick expression with an -exec argument to find.
This seems to be the case when I build with --enable-shared as well -- then there is only one hit (./.lib/libnettle-4-3.dll), but it is not under testsuite/. Should there be more *.dll files?
For a native build: That's how it should be. The .lib directory is added to PATH, which should be sufficient for running the testprograms. The additional symlinks in the testsuite and example directories should be there only when cross compiling (detected by $EMULATOR matching wine*).
Regards, /Niels
nisse@lysator.liu.se (Niels Möller) writes:
Simon Josefsson simon@josefsson.org writes:
With MinGW-64 I got the following error when building:
For clarity: Is this MinGW-64 *natively* on a windows machine, or a cross compiler?
Cross-compiler, running on a Debian Squeeze machine.
This seems to be the case when I build with --enable-shared as well -- then there is only one hit (./.lib/libnettle-4-3.dll), but it is not under testsuite/. Should there be more *.dll files?
For a native build: That's how it should be. The .lib directory is added to PATH, which should be sufficient for running the testprograms. The additional symlinks in the testsuite and example directories should be there only when cross compiling (detected by $EMULATOR matching wine*).
I have the binfmt-support package installed, so an emulator is not strictly required -- i.e., running ./foo.exe will work directly and using 'wine ./foo.exe' is not necessary. Will $EMULATOR be empty in this case?
/Simon
Simon Josefsson simon@josefsson.org writes:
I have the binfmt-support package installed, so an emulator is not strictly required -- i.e., running ./foo.exe will work directly and using 'wine ./foo.exe' is not necessary. Will $EMULATOR be empty in this case?
It will most likely have been set automatically to wine64. Check the substituted variable in config.make. Do you think some additional configure tests are needed? (Alternatively, one could do something similar to automake's "make check TESTS_ENVIRONMENT=wine", but that's not as general since some of the test programs are shell scripts, not windows executables).
But I think I have found out why the links weren't created. I forgot to set the executable bit on testsuite/setup-env. And since this is still cvs, that's a bit painful to get fixed. *sigh*
Regards, /Niels
From: nisse@lysator.liu.se (Niels Möller) Cc: nettle-bugs@lists.lysator.liu.se Date: Tue, 17 Jan 2012 13:58:37 +0100
I also found out that dlls apperantly weren't linked into the .lib directory, so I tried to fix that as well. This directory is added to LD_LIBRARY_PATH (for ELF systems) and PATH (for windows), when running the testsuite.
Unfortunately, I couldn't figure out how to get wine to add the .lib directory to the initial PATH.
Is that a wine-specific problem, or a general Windows problem? If the latter, maybe I can help if you describe the difficulty.
I just put up a prerelease at http://www.lysator.liu.se/~nisse/archive/nettle-2.5-pre.tar.gz (and .sig), any testing (in particular on windows) is appreciated.
Thanks, I will try to do this as soon as I have time.
Eli Zaretskii eliz@gnu.org writes:
Unfortunately, I couldn't figure out how to get wine to add the .lib directory to the initial PATH.
Is that a wine-specific problem, or a general Windows problem?
That's wine specific. Wine copies most environment variables from the unix environment it is started from into the environment of the executed windows program. With some exceptions for "special" environment variables, including PATH. After a quick look at the source code, it looks one should be able to set WINEPATH when starting wine, and have that copied to the windows path (possibly without any automagic translation of the filenames). But I couldn't get that to work.
Anyway, it's a wine-specific problem, and I have a workaround.
Regards, /Niels
nettle-bugs@lists.lysator.liu.se