VS2010 compile Mosquitto Win32 version, turn on WebSockets, implement message push

Source: Internet
Author: User
Tags install openssl

Preface: Because did not have how to touch vs, only has had the Cygwin, but the Cygwin has been engaged for a long time to make uncertain, so as to reorganize the thought, this window version should how to compile. Always do not know how to do, can only watch other tutorials, the side of their own, a few days under the class can study the compilation, especially in the opening websockets, plus Libwebsockets Library, for small white, especially painful. Finally, it compiles successfully.

Compiled PC: MacBook Pro virtual machine win7,64bit,1.5g memory
Reference: http://blog.csdn.net/Netown_Ethereal/article/details/41981103

Talk less, start ~

1. Download vs2010

I have a flagship version, but only a 30-day trial, no harm, the compilation is enough.
Http://www.xpgod.com/soft/6637.html
PS: Before using vs2008 to compile, and then various inexplicable, if there are classmates know why, please leave a message.

2. Lower the required libraries.

C-ares http://c-ares.haxx.se/I was the newest 1.10.0,c-ares-1.10.0.tar.gz of the time.
Pthreads Ftp://sourceware.org/pub/pthreads-win32 2.9.1,pthreads-w32-2-9-1-release.zip
OpenSSL http://www.openssl.org/related/binaries.html I was under the latest 1.0.2a,win32openssl-1_0_2a.exe.
CMake http://www.cmake.org/download/I was the newest 3.2.2,cmake-3.2.2-win32-x86.exe of the time.
Libwebsocket http://git.warmcat.com/cgi-bin/cgit/libwebsockets/1.4,libwebsockets-1.4-chrome43-firefox-36.tar.gz
Mosquitto http://mosquitto.org/download/I was the newest 1.4.2,mosquitto-1.4.2.tar.gz of the time.

3. Install the library.

installation files, source files are placed in C:\application\
1) First install the vs2010, I was completely installed, in order to reduce the impact of other factors.
2) Unzip the C-ares, the path is C:\application\c-ares-1.10.0
3) Unzip the pthreads and copy the pre-built.2 include file to C:\Program files (x86) \microsoft Visual Studio 10.0\vc\include
Pre-built.2 lib files copied to C:\Program files (x86) \microsoft Visual Studio 10.0\vc\lib
4) Install OpenSSL, path is C:\OpenSSL-Win32
5) Install the CMake and generate the Cmake-gui.exe program from the Start menu.
6) Decompression Libwebsocket, this is the source, need to vs2010 compile a bit.
Open Cmake-gui, as follows

In the third step, pop up a dialog box, choose Visual Studio 10 2010, do not select 64bit, remember.
Wait a moment, as follows

In C:\build-websocket, you create a vs project, find Libwebsockets.sln, and double-click Open.

Generates something more important, which is used in the following:
C:\build-websocket\bin\MinSizeRel Libeay32.dll Ssleay32.dll Websockets.dll
C:\build-websocket\lib\MinSizeRel Websockets.lib ZLIB.lib

7) Unzip the Mosquitto, the path is C:\application\mosquitto-1.4.2

4. Prepare to compile mosquitto1.4.2

Open the Cmake-gui, then point to the first step, then the last appearance c-ares can't find

Then configure the relevant options, as follows

Here C:\build, with vs2010 open Mosquitto.sln, in the "Output" window to find a lot of errors

It turns out that these files are caused by the day of the week of the date string. So the above mentioned files in the garbled deletion, that is, "weeks" deleted, such as:

Error in Mosquittopp.vcxproj file, name cannot start with ">" character (hexadecimal value 0x3e). There are several similar changes in the back.

Reopen the Mosquitto.sln, and the project right-click starts to build.

Report a push error, to the effect that the Libwebsockcets function can not be found.

In Solution Explorer, locate Mosquitto, right-click, properties.

In the Mosquitto property page that opens, turn on configuration properties, linker, input, additional dependencies.

Click on the small triangle on the right to go out and attach the Dependencies page. Change the final websockets.lib to the correct lib file path.

Re-compile the project right-click.

If you encounter the inability to open mosquitto.lib, indicating that a sub-project needs to rely on Libmosquitto this project, in the sub-project right-click "Project Dependencies" inside the Libmosquitto can be checked.

If you encounter a heap of red errors and cannot parse the external symbols, it indicates that some libraries do not have references, and that the corresponding Lib should be added to the additional dependencies. or copy to
C:\Program Files (x86) \microsoft Visual Studio 10.0\vc\lib

If you encounter a missing. h header file, you need to copy the corresponding header file to C:\Program files (x86) \microsoft Visual Studio 10.0\vc\include

At this point the main program is:
C:\build\src\MinSizeRel\mosquitto.exe
C:\build\src\MinSizeRel\mosquitto_passwd.exe

C:\build\client\MinSizeRel\mosquitto_pub.exe
C:\build\client\MinSizeRel\mosquitto_sub.exe

Of course, it is also possible to choose release here.

If you want to put the generated things together, it is necessary to fill out the output path. Sub-project Right-click Properties, Configuration Properties, general, Output directory, change dimension c:\build\output\, and other sub-projects are also modified.

After you change it, regenerate it.

At this time, still can't open the main program, the hint is missing websockets.lib,
So copy C:\build-websocket\lib\MinSizeRel\websockets.lib-C:\build\output
And then move the W file you need, as follows.
C:\application\mosquitto-1.4.2\mosquitto.conf-C:\build\output
C:\build-websocket\bin\MinSizeRel\libeay32.dll-C:\build\output
C:\build-websocket\bin\MinSizeRel\ssleay32.dll-C:\build\output
C:\pthreads\Pre-built.2\dll\x86\pthreadVC2.dll-C:\build\output
Now the directory is as follows: open to see, can run.

First of all, mosquitto.conf in the extra listeners open: Listener 9001,protocol websockets
Test the way that Mqtt and WebSockets are turned on at the same time:

In case of error 0x0000007d, install Vcredist2010_x86.exe can be solved.

PS: Before the completion of the compilation encountered many problems, VS2010 reported a lot of errors, not solve, especially the final compilation by opening EXE on the application does not start normally (0xc000007b). Especially vomiting blood, in despair, found that 64-bit compilation using 32-bit library, or 32-bit compilation using 64-bit library back to this situation, so I put the original CMake generation vs project configuration from vs2010 x64, changed to VS2010 x86, That is, later VS2010 main interface display WIN32, instead of x64, pit for a long time, anyway, after remembering, whether the system is 64-bit, all use 32-bit library and 32-bit compilation.

To this, compile the completion, I will upload the compilation process to CSDN, stay tuned.

Supplemental Resources Link: Point me to jump

VS2010 compile Mosquitto Win32 version, turn on WebSockets, implement message push

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.