NOTE: The instructions and examples are based on Windows 10.
EMQX includes Erlang NIF (Native Implemented Function) components, implemented in C/C++. To compile and link C/C++ libraries, the easiest way is perhaps to install Visual Studio.
Visual Studio 2019 is used in our tests. If you are like me (@zmstone), do not know where to start, please follow this OTP guide: https://github.com/erlang/otp/blob/master/HOWTO/INSTALL-WIN32.md
NOTE: To avoid surprises, you may need to add below two paths to Path
environment variable
and order them before other paths.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx64\x64
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build
Depending on your visual studio version and OS, the paths may differ.
The first path is for rebar3 port compiler to find cl.exe
and link.exe
The second path is for CMD to setup environment variables.
Install Erlang/OTP 24 from https://www.erlang.org/downloads
You may need to edit the Path
environment variable to allow running
Erlang commands such as erl
from powershell.
To validate Erlang installation in CMD or powershell:
-
Start (or restart) CMD or powershell
-
Execute
erl
command to enter Erlang shell -
Evaluate Erlang expression
halt().
to exit Erlang shell.
e.g.
PS C:\Users\zmsto> erl
Eshell V12.2.1 (abort with ^G)
1> halt().
All EMQX build/run scripts are either in bash
or escript
.
escript
is installed as a part of Erlang. To install a bash
environment in Windows, there are quite a few options.
Cygwin is what we tested with.
-
Add
cygwin\bin
dir toPath
environment variable To do so, search for Edit environment variable in control panel and addC:\tools\cygwin\bin
(depending on the location where it was installed) toPath
list. -
Validate installation. Start (restart) CMD or powershell console and execute
which bash
, it should print out/usr/bin/bash
NOTE: Make sure cygwin's bin dir is added before C:\Windows\system32
in Path
,
otherwise the build scripts may end up using binaries from wsl instead of cygwin.
Some of the unix world tools are required to build EMQX. Including:
- git
- curl
- make
- cmake
- jq
- zip / unzip
We recommend using scoop, or Chocolatey to install the tools.
When using scoop:
scoop install git curl make cmake jq zip unzip
-
Clone the repo:
git clone https://github.com/emqx/emqx.git
-
Start CMD console
-
Execute
vcvarsall.bat x86_amd64
to load environment variables -
Change to emqx directory and execute
make
-
'cl.exe' is not recognized as an internal or external command
This error is likely due to Visual Studio executables are not set inPath
environment variable. To fix it, either add path likeC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx64\x64
toPaht
. Or make surevcvarsall.bat x86_amd64
is executed prior to themake
command -
fatal error C1083: Cannot open include file: 'assert.h': No such file or directory
If Visual Studio is installed correctly, this is likelyLIB
andLIB_PATH
environment variables are not set. Make surevcvarsall.bat x86_amd64
is executed prior to themake
command -
link: extra operand 'some.obj'
This is likely due to the usage of GNUlnik.exe
but not the one from Visual Studio. Executelink.exe --version
to inspect which one is in use. The one installed from Visual Studio should print outMicrosoft (R) Incremental Linker
. To fix it, Visual Studio's bin paths should be ordered prior to Cygwin's (or similar installation's) bin paths inPath
environment variable.
To start EMQX broker.
Execute _build\emqx\rel\emqx>.\bin\emqx console
or _build\emqx\rel\emqx>.\bin\emqx start
to start EMQX.
Then execute _build\emqx\rel\emqx>.\bin\emqx_ctl status
to check status.
If everything works fine, it should print out
Node '[email protected]' 4.3-beta.1 is started
Application emqx 4.3.0 is running