Mosquitto Build Notes (Windows Visual Studio) Feb 16 2015 - bapowell/bapowell.github.io GitHub Wiki
Build Mosquitto (with websockets) on Windows - Visual Studio
Install prerequisite software
Download and install Visual Studio Express 2015 for Windows Desktop.
- Note: This took several hours to install.
Download and unzip cmake.
Download and install Win32 OpenSSL.
- https://slproweb.com/products/Win32OpenSSL.html
- Tested with v1.0.2e Light.
- Note that you might actually need the full OpenSSL install to compile with TLS support.
- Installed to c:\temp\OpenSSL-Win32\
Download and unzip pthreads-win32.
- ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip
- Unzip to c:\pthreads\ (cmake/make won't find it otherwise)
Build libwebsockets
Download and extract the libwebsockets source code.
- http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets-1.6.2.tar.gz
- Build notes at https://github.com/warmcat/libwebsockets/blob/master/README.build.md
- Extracted to c:\temp\libwebsockets-1.6.2
Create folder for the build.
- c:\temp\libwebsockets-1.6.2\build\
Use cmake (or cmake-gui) to generate the Visual Studio project solution.
- Should be generated to c:\temp\libwebsockets-1.6.2\build\
- See this link to find out the version number corresponding to your Visual Studio edition: http://superuser.com/a/194065
- Generator for Visual Studio Express 2015 is "Visual Studio 14 2015".
- After Configure step, errors indicated couldn't find OpenSSL-related items:
- Added OPENSSL_ROOT_DIR, pointed to c:\temp\OpenSSL-Win32\
- Changed CMAKE_INSTALL_PREFIX to c:\temp\libwebsockets (although not sure this really mattered)
- Generated again.
Open and build solution in Visual Studio.
- C:\Temp\libwebsockets-1.6.2\build\libwebsockets.sln
- Before building, in Visual Studio menu bar select "Release" and "Win32".
- Build.
Build Mosquitto
Download and extract the Mosquitto source code.
- http://mosquitto.org/files/source/mosquitto-1.4.7.tar.gz
- Extracted to c:\temp\mosquitto-1.4.7\
Create folder for the build
- C:\Temp\mosquitto-1.4.7\build\
Use cmake (or cmake-gui) to generate the Visual Studio project solution.
- Should be generated to c:\temp\mosquitto-1.4.7\build\
- See this link to find out the version number corresponding to your Visual Studio edition: http://superuser.com/a/194065
- Generator for Visual Studio Express 2015 is "Visual Studio 14 2015".
- After Configure step, errors indicated couldn't find OpenSSL-related items:
- Added OPENSSL_ROOT_DIR, pointed to c:\temp\OpenSSL-Win32\
- After Generate again, error indicated c-ares library not found.
- Unchecked the WITH_SRV option, and generated again.
- Checked the WITH_WEBSOCKETS option.
- Changed CMAKE_INSTALL_PREFIX to c:\temp\mosquitto (although not sure this really mattered).
- Generated again.
Open and build solution in Visual Studio.
- C:\Temp\mosquitto-1.4.7\build\mosquitto.sln
- Include directory paths for libwebsockets:
- Right-click "mosquitto" project in Solution Explorer --> Properties --> VC++ Directories -->
- Include Directories --> (add paths) ... :
- C:\Temp\libwebsockets-1.6.2\libwebsockets-1.6.2\lib (for libwebsockets.h)
- C:\Temp\libwebsockets-1.6.2\build (for lws_config.h)
- Library Directories --> (add paths) ... :
- C:\Temp\libwebsockets-1.6.2\build\lib\Release (for websockets.lib)
- Include Directories --> (add paths) ... :
- Right-click "mosquitto" project in Solution Explorer --> Properties --> VC++ Directories -->
- Before building, in Visual Studio menu bar select "Release" and "Win32".
- Build.
- Correcting build errors:
- In C:\Temp\mosquitto-1.4.7\config.h, had to remove line 15: "#define snprintf sprintf_s"
- In C:\pthreads\Pre-built.2\include\pthread.h, commented out the struct timespec, lines 320-323.
- Executables and libraries are in:
- C:\Temp\mosquitto-1.4.7\build\src\Release (mosquitto.exe, mosquitto_passwd.exe)
- C:\Temp\mosquitto-1.4.7\build\client\Release (mosquitto_pub.exe, mosquitto_sub.exe)
- C:\Temp\mosquitto-1.4.7\build\lib\Release (mosquitto.dll, mosquitto.lib)
Test
Before running:
- Copy the following dll files to C:\Temp\mosquitto-1.4.7\build\src\Release :
- C:\temp\OpenSSL-Win32\bin\libeay32.dll
- C:\temp\OpenSSL-Win32\bin\ssleay32.dll
- C:\temp\libwebsockets-1.6.2\build\bin\Release\websockets.dll
Run
C:\Temp\mosquitto-1.4.7\build\src\Release\mosquitto.exe -v -c {config file}