2019/11/13 亲测可用,但是有坑。见下方 Win10 X64 编译方法。
The nanomsg library is a simple high-performance implementation of several "scalability protocols". These scalability protocols are light-weight messaging protocols which can be used to solve a number of very common messaging patterns, such as request/reply, publish/subscribe, surveyor/respondent, and so forth. These protocols can run over a variety of transports such as TCP, UNIX sockets, and even WebSocket.
For more information check the website.
-
Windows.
- Windows Vista or newer (Windows XP and 2003 are NOT supported)
- Microsoft Visual Studio 2010 (including C++) or newer, or mingw-w64. (Specifically mingw and older Microsoft compilers are *NOT supported, and we do not test mingw-w64 at all, so YMMV.)
- CMake 2.8.7 or newer, available in $PATH as
cmake
-
POSIX (Linux, MacOS X, UNIX)
- ANSI C compiler supporting C89
- POSIX pthreads (should be present on all modern POSIX systems)
- BSD sockets support for both TCP and UNIX domain sockets
- CMake (http://cmake.org) 2.8.7 or newer, available in $PATH as
cmake
-
Documentation (optional)
- asciidoctor (http://asciidoctor.org/) available as
asciidoctor
- If not present, docs are not formatted, but left in readable ASCII
- Also available on-line at http://nanomsg.org/documentation
- asciidoctor (http://asciidoctor.org/) available as
These steps here are the minimum steps to get a default Debug build. Using CMake you can do many other things, including setting additional variables, setting up for static builds, or generation project or solution files for different development environments. Please check the CMake website for all the various options that CMake supports.
This assumes you have a shell in the project directory, and have the cmake and suitable compilers (and any required supporting tools like linkers or archivers) on your path.
% mkdir build
% cd build
% cmake ..
% cmake --build .
% ctest .
% sudo cmake --build . --target install
% sudo ldconfig
(if on Linux)
This assumes you are in a command or powershell window and have
the appropriate variables setup to support Visual Studio, typically
by running vcvarsall.bat
or similar with the appropriate argument(s).
It also assumes you are in the project directory.
md build
cd build
cmake ..
cmake --build . --config Debug
ctest -C Debug .
cmake --build . --config Debug --target install
NB: This may have to be done using an Administrator account.
上面那个编译出来的,可能是32位(X86)的 nanomsg,不能用。改一下编译的方法,这里使用的 VS2017。
- 百度 Cmake,进入下载页面 https://cmake.org/download/
- 下载 Cmake,当前的最新版本为 Latest Release (3.15.5)。
- 安装 Cmake,注意选择加入 Path,方便以后使用。
- 运行 CMD,输入 Cmake,能运行说明安装成功了。接下来就可以开始编译 nanomsg 了。
在 nanomsg github release 中下载要用的版本的 Zip,当前使用 Release 1.1.5。解压。
右键 Windows 图标,运行 Windows PowerShell(管理员),不用 CMD 因为丑。cd 到解压后的 nanomsg 根目录。
md build
cd build
cmake -G "Visual Studio 15 Win64" ..
cmake --build . --config Debug
ctest -C Debug .
cmake --build . --config Debug --target install
不在第3步加-DNN_STATIC_LIB=ON
。编译好的 nanomsg 会出现在 C:\Program Files\nanomsg。如果弄成了32位,就会出现在 C:\Program Files(x86)\nanomsg。这个 nanomsg 文件夹包含 .h/lib/dll。
以 C++ 控制台程序举例
- 打开 VS,新建一个 C++ 控制台项目。
- 将上面得到的 /.h/lib/dll 弄到项目目录下。
- 用他
We normally build a dynamic library (.so or .DLL) by default.
If you want a static library (.a or .LIB), configure by passing
-DNN_STATIC_LIB=ON
to the first cmake
command.
POSIX systems will need to link with the libraries normally used when building network applications. For some systems this might mean -lnsl or -lsocket.
You will also need to define NN_STATIC_LIB
in your compilation environment
when building programs that use this library. This is required because of
the way Windows changes symbol names depending on whether the symbols should
be exported in a DLL or not.
When using the .LIB on Windows, you will also need to link with the ws2_32, mswsock, and advapi32 libraries, as nanomsg depends on them.
This library is considered to be in "sustaining" mode, which means that new feature development has ended, and bug fixes are made only when strictly necessary for severe issues.
New development is now occurring in the NNG project, which offers both protocol and API compatibility with this project. Please consider using NNG for new projects.
Please see the file SUPPORT for more details.
Website: http://nanomsg.org
Source code: https://github.com/nanomsg/nanomsg
Documentation: http://nanomsg.org/documentation.html
Bug tracker: https://github.com/nanomsg/nanomsg/issues
Mailing list: [email protected]
Gitter Chat: https://gitter.im/nanomsg/nanomsg
IRC chatroom: #nanomsg at irc.freenode.net/8001