Unable to compile fast_tls on Windows issue

Viewed 67

I'm not sure if this has already been covered in a previous post. I was following along to a blog on building a stun server for Phoenix and reference was made to an issue due to openssl headers.

https://github.com/processone/ejabberd/issues/1107#issuecomment-217828211

This covered I believe solutions for Mac OS x operating system. I tried to reproduce the installation on a Windows 10 machine, however I have run into problems. This was working on a downloaded package:

https://github.com/processone/fast_tls

I unzipped and ran a bash emulator (git bash by right-clicking the fast-tls-master folder and clicking on Git Bash Here. I also downloaded a make program from Chocolatety.

This is the output when I followed along to the instructions in the README:

Paul@paul-pc03 MINGW64 ~/Downloads/fast_tls-master/fast_tls-master

$ export LDFLAGS="-LC:/msys64/mingw64/lib"
$ export CFLAGS="-IC:/msys64/mingw64/include/"
$ export CPPFLAGS="-IC:/msys64/mingw64/include/"

$ ./configure && make

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether make sets $(MAKE)... yes
checking for an ANSI C-conforming const... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for ANSI C header files... (cached) yes
checking for erl... /c/Program Files/erl-24.3.4.2/bin/
erl
checking for erlc... /c/Program Files/erl-24.3.4.2/bin/erlc
checking for SSL_free in -lssl... yes
checking for SHA1_Init in -lcrypto... yes
checking openssl/ssl.h usability... yes
checking openssl/ssl.h presence... yes
checking for openssl/ssl.h... yes
checking openssl/err.h usability... yes
checking openssl/err.h presence... yes
checking for openssl/err.h... yes
checking openssl/sha.h usability... yes
checking openssl/sha.h presence... yes
checking for openssl/sha.h... yes
checking openssl/opensslv.h usability... yes
checking openssl/opensslv.h presence... yes
checking for openssl/opensslv.h... yes
configure: creating ./config.status
config.status: creating vars.config
rebar get-deps compile
process_begin: CreateProcess(NULL, rebar 
get-deps compile, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:6: src] Error 2

Paul@paul-pc03 MINGW64 ~/Downloads/fast_tls-master/fast_tls-master

I also noted that errors were produced in a config.log file.

conftest.c:9:10: fatal error: ac_nonexistent.h: 
No such file or directory
    9 | #include <ac_nonexistent.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
configure:2991: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "tls"
| #define PACKAGE_TARNAME "tls"
| #define PACKAGE_VERSION "1.0.10"
| #define PACKAGE_STRING "tls 1.0.10"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #include <ac_nonexistent.h>

I've no idea how relevant this is, but it is clear that the install didn't work. There was some sparse output in a vars.config file:

{cflags, "-IC:/msys64/mingw64/include/ -Wall"}.
{ldflags, "-LC:/msys64/mingw64/lib"}.
{with_gcov, "false"}.

%% Local Variables:
%% mode: erlang
%% End:
%% vim: set filetype=erlang tabstop=8:

Well, if anyone has any ideas on how to proceed, it would be very much welcomed. I'm wondering whether this may not be possible on a Windows machine?

Best regards,

Paul.

MadScientist: You are quite correct!! Thank you. Yes, after looking at my system I can see that it is indeed installed in my Windows user .mix directory. I have come across it in the past while building Phoenix Elixir web apps, installing it on-the-fly without paying much attention to it - on googling it further I see that it is a build tool necessary for Erlang apps. I updated my env vars and re-ran, but alas it brought me back to the very thing I was trying to avoid - previously I ran an Elixir mix compile command on a dependency called fast_tls - on that occasion the mix rebar commands then kicked off a Microsoft Visual Studio build tool called cl.exe that in turn ran a MSVC c++ compiler, and it is there that I have run into a complete block. Essentially it's telling me: "your fast_tls.c program or your mingw64 include files (eg stdio.h, stdlib.h) have errors (referencing various MSVC code errors, for example C2143, C2059, C2085, C4668, C4820). Correct them and then re-submit your program." On futher googling I can see previous occurrences of exactly the same compiler issues - due to the nature of the MSVC compiler's strict adherence to various type/macro/class calling conventions and signatures. I am by no means a C++ expert and now feel quite lost on how to move on with this. For this reason I am asking if anyone else has had experience of this, and how they managed to move on. Maybe there is a way to avoid using cl.exe for Windows?

To re-cap, here are the 2 ways I tried to compile fast_tls:

Method 1) mix compile

contents of mix.exs:

defp deps do
  [
    ...
    {:fast_tls, "~> 1.1.15"},
    # {:stun, "~> 1.0"}
  ]

C:\Users\Paul\Desktop\phoenix\els_umbrella>set LDFLAGS="-LC:/msys64/mingw64/lib"
C:\Users\Paul\Desktop\phoenix\els_umbrella>set CPPFLAGS="-IC:\msys64\mingw64\include"
C:\Users\Paul\Desktop\phoenix\els_umbrella>set CFLAGS="-IC:\msys64\mingw64\include"

C:\Users\Paul\Desktop\phoenix\els_umbrella>mix compile
===> Compiling c:/Users/Paul/Desktop/phoenix/els_umbrella/deps/fast_tls/c_src/fast_tls.c
===> Microsoft (R) C/C++ Optimizing Compiler Version 19.32.31332 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '-g'
fast_tls.c
C:\msys64\mingw64\include\_mingw_mac.h(215): warning C4668: '__GNUC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
C:\msys64\mingw64\include\_mingw_mac.h(306): warning C4668: '_FORTIFY_SOURCE' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
C:\msys64\mingw64\include\stdio.h(39): warning C4820: '_iobuf': '4' bytes padding added after data member '_cnt'
C:\msys64\mingw64\include\stdio.h(577): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(584): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(590): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(851): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(881): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1235): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1242): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1248): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1364): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1374): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\swprintf.inl(27): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\swprintf.inl(34): error C2059: syntax error: 'type'
c:\Program Files\erl-24.3.4.2\erts-12.3.2.2\include\erl_drv_nif.h(40): warning C4820: '<unnamed-tag>': '4' bytes padding added after data member 'dirty_scheduler_support'
c:\Program Files\erl-24.3.4.2\erts-12.3.2.2\include\erl_drv_nif.h(156): warning C4820: '_SysIOVec': '4' bytes padding added after data member 'iov_len'
C:\msys64\mingw64\include\stdlib.h(389): error C2085: '_exit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(389): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(396): error C2085: '_Exit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(396): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(399): error C2085: '_Exit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(399): error C2143: syntax error: missing ';' before '{'
C:\msys64\mingw64\include\stdlib.h(399): warning C4013: '_exit' undefined; assuming extern returning int
C:\msys64\mingw64\include\stdlib.h(399): error C2065: 'status': undeclared identifier
C:\msys64\mingw64\include\stdlib.h(405): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdlib.h(683): error C2491: '_beep': definition of dllimport function not allowed
C:\msys64\mingw64\include\stdlib.h(685): error C2085: '_seterrormode': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(685): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(686): error C2085: '_sleep': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(686): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(707): error C2085: 'ecvt': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(708): error C2085: 'fcvt': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(709): error C2085: 'gcvt': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(710): error C2085: 'itoa': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(711): error C2085: 'ltoa': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(712): error C2085: 'putenv': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(716): error C2085: 'swab': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(719): error C2085: 'ultoa': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(720): error C2085: 'onexit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(726): error C2085: 'lldiv_t': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(728): error C2061: syntax error: identifier 'lldiv_t'
C:\msys64\mingw64\include\stdlib.h(732): error C2169: 'llabs': intrinsic function, cannot be defined
C:\msys64\mingw64\include\malloc.h(50): warning C4820: '_heapinfo': '4' bytes padding added after data member '_useflag'
C:\msys64\mingw64\include\malloc.h(82): fatal error C1083: Cannot open include file: 'mm_malloc.h': No such file or directory

** (Mix) Could not compile dependency :fast_tls, "escript.exe "c:/Users/Paul/.mix/rebar3" bare compile --paths c:/Users/Paul/Desktop/phoenix/els_umbrella/_build/dev/lib/*/ebin" command failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile fast_tls", update it with "mix deps.update fast_tls" or clean it with "mix deps.clean fast_tls"

Method 2) Run bash emulator on fast_tls_master:

Paul@paul-pc03 MINGW64 ~/Downloads/fast_tls-master/fast_tls-master
$ export LDFLAGS="-LC:/msys64/mingw64/lib"

$ export CFLAGS="-IC:/msys64/mingw64/include/"

$ export CPPFLAGS="-IC:/msys64/mingw64/include/"

Paul@paul-pc03 MINGW64 ~/Downloads/fast_tls-master/fast_tls-master
$ ./configure && make
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether make sets $(MAKE)... yes
checking for an ANSI C-conforming const... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for ANSI C header files... (cached) yes
checking for erl... /c/Program Files/erl-24.3.4.2/bin/erl
checking for erlc... /c/Program Files/erl-24.3.4.2/bin/erlc
checking for SSL_free in -lssl... yes
checking for SHA1_Init in -lcrypto... yes
checking openssl/ssl.h usability... yes
checking openssl/ssl.h presence... yes
checking for openssl/ssl.h... yes
checking openssl/err.h usability... yes
checking openssl/err.h presence... yes
checking for openssl/err.h... yes
checking openssl/sha.h usability... yes
checking openssl/sha.h presence... yes
checking for openssl/sha.h... yes
checking openssl/opensslv.h usability... yes
checking openssl/opensslv.h presence... yes
checking for openssl/opensslv.h... yes
configure: creating ./config.status
config.status: creating vars.config
C:\Users\Paul\.mix\rebar get-deps compile
==> p1_utils (get-deps)
==> fast_tls-master (get-deps)
==> p1_utils (compile)
==> fast_tls-master (compile)
Compiling c_src/fast_tls.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.32.31332 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

fast_tls.c
C:\msys64\mingw64\include\_mingw_mac.h(215): warning C4668: '__GNUC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
C:\msys64\mingw64\include\_mingw_mac.h(306): warning C4668: '_FORTIFY_SOURCE' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
C:\msys64\mingw64\include\stdio.h(39): warning C4820: '_iobuf': '4' bytes padding added after data member '_cnt'
C:\msys64\mingw64\include\stdio.h(577): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(584): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(590): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(851): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(881): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1235): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1242): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1248): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1364): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdio.h(1374): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\swprintf.inl(27): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\swprintf.inl(34): error C2059: syntax error: 'type'
c:\Program Files\erl-24.3.4.2\erts-12.3.2.2\include\erl_drv_nif.h(40): warning C4820: '<unnamed-tag>': '4' bytes padding added after data member 'dirty_scheduler_support'
c:\Program Files\erl-24.3.4.2\erts-12.3.2.2\include\erl_drv_nif.h(156): warning C4820: '_SysIOVec': '4' bytes padding added after data member 'iov_len'
C:\msys64\mingw64\include\stdlib.h(389): error C2085: '_exit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(389): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(396): error C2085: '_Exit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(396): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(399): error C2085: '_Exit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(399): error C2143: syntax error: missing ';' before '{'
C:\msys64\mingw64\include\stdlib.h(399): warning C4013: '_exit' undefined; assuming extern returning int
C:\msys64\mingw64\include\stdlib.h(399): error C2065: 'status': undeclared identifier
C:\msys64\mingw64\include\stdlib.h(405): error C2059: syntax error: 'type'
C:\msys64\mingw64\include\stdlib.h(683): error C2491: '_beep': definition of dllimport function not allowed
C:\msys64\mingw64\include\stdlib.h(685): error C2085: '_seterrormode': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(685): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(686): error C2085: '_sleep': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(686): error C2143: syntax error: missing ';' before 'type'
C:\msys64\mingw64\include\stdlib.h(707): error C2085: 'ecvt': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(708): error C2085: 'fcvt': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(709): error C2085: 'gcvt': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(710): error C2085: 'itoa': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(711): error C2085: 'ltoa': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(712): error C2085: 'putenv': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(716): error C2085: 'swab': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(719): error C2085: 'ultoa': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(720): error C2085: 'onexit': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(726): error C2085: 'lldiv_t': not in formal parameter list
C:\msys64\mingw64\include\stdlib.h(728): error C2061: syntax error: identifier 'lldiv_t'
C:\msys64\mingw64\include\malloc.h(50): warning C4820: '_heapinfo': '4' bytes padding added after data member '_useflag'
C:\msys64\mingw64\include\malloc.h(82): fatal error C1083: Cannot open include file: 'mm_malloc.h': No such file or directory
ERROR: compile failed while processing c:/Users/Paul/Downloads/fast_tls-master/fast_tls-master: rebar_abort
make: *** [Makefile:6: src] Error 1

Paul@paul-pc03 MINGW64 ~/Downloads/fast_tls-master/fast_tls-master

I have installed Microsoft Visual Studio Community Edition 2020, and the system env path to the cl.exe program is:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64;

After some conversations re: processone/ejabberd, we tried to run Windows 10 mix compile on fast_tls again.

The problem in Windows 10 mix compile appears to be with fetching a certain "pc v1.14.0" - called by p1_utils and fast_tls - we are informed that pc is a port_compiler, used for compiling C code, required by several ejabberd dependencies that include C code, all the fast_*.

When we compile fast_tls we are dumped out with a default Visual Studio cl.exe batch script that clearly doesn't understand any of the passed in params, but instead writes out a "vc140.pdb (program debug file). We also see that no files are written to the c_src sub-directory within fast_tls (normally object files etc are written out here during the compile stage). There is also an _ebin folder written out - which one assumes contains an attempt to produce erlang beam files and config.

We have a wls (Windows Subsystem for Linux) soft-link pointing to the same fast_tls folder. When we run the Elixir mix compile in wsl, we can see that indeed files are written to the c_src sub-directory (.o and .d files among others), and the _ebin folder is updated with what appears to be correctly configured erlang beam files and config. We also receive an Elixir mix compile success message.

If we then re-run the same Elixir mix compile, but this time in Windows and not wsl against fast_tls, the command also succeeds with no further action taken. We can see that all files in the fast_tls folder are preserved and no timestamps are updated. The _ebin folder is not updated and remains intact. We can't confirm if these are actually usable - since they were written out by wsl linux and not Windows, but we can then go ahead and install the stun dependency (which requires fast_tls) in Windows using mix deps.get, and the dependency appears to install without errors.

But we are completely lost as to how to make the windows version compile like the linux version in the first place.

We have checked the rebar config - these appear to be files that can't be edited - and all the environment variables - but we simply cannot see how to tell the windows version to compile fast_tls like the linux one - presumably calling the pc port compiler instead of running a default MSCV compiler ... We don't have experience in managing Erlang configs, we can handle it in Elixir mix, but that is the limit of our knowledge. Maybe there are examples out there on how to use the port_compiler on Microsoft Windows. Any ideas would be very much welcomed as we are now at a dead end!

This issue can now be closed. The fix has been provided: https://github.com/processone/stun/issues/37 Many thanks to all at processone!

0 Answers
Related