2019年4月25日 星期四

Static and dynamic link ZeroMQ on Windows for Visual Studio 2017 x64




Static ZeroMQ (difficult setup)

cd /d C:\
mkdir Repos
cd /d C:\Repos\
git clone https://github.com/Microsoft/vcpkg
cd /d C:\Repos\vcpkg\
bootstrap-vcpkg.bat
cd /d C:\Repos\vcpkg\
vcpkg install zeromq:x64-windows-static

Visual Studio 2017 creates empty project and a.cpp
#include <zmq.h>
#include <iostream>

#ifdef _DEBUG
#pragma comment(lib,"libzmq-mt-sgd-4_3_2.lib")
#else
#pragma comment(lib,"libzmq-mt-s-4_3_2.lib")
#endif
#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"Iphlpapi.lib")
 
int main()
{
 int major = 0;
 int minor = 0;
 int patch = 0;
 zmq_version( &major, &minor, &patch );
 std::wcout << "Current 0MQ version is " << major << '.' << minor << '.' << patch << '\n';
}

Copy files to folder of a.cpp from
C:\Repos\vcpkg\packages\zeromq_x64-windows-static\include
zmq.h
zmq_utils.h
Copy from C:\Repos\vcpkg\packages\zeromq_x64-windows-static\lib\libzmq-mt-s-4_3_2.lib
C:\Repos\vcpkg\packages\zeromq_x64-windows-static\debug\lib\libzmq-mt-sgd-4_3_2.lib

Preprocessor Definitions:
ZMQ_STATIC

Debug Code Generation from /MDd to /MTd
Release Code Generation from /MD to /MT


Dynamic ZeroMQ (simpler setup)


cd /d C:\Repos\vcpkg\
vcpkg install zeromq:x64-windows

Visual Studio 2017 creates empty project and a.cpp
#include "zmq.h"
#include <iostream>

#ifdef _DEBUG
#pragma comment(lib,"libzmq-mt-sgd-4_3_2.lib")
#else
#pragma comment(lib,"libzmq-mt-s-4_3_2.lib")
#endif
#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"Iphlpapi.lib")
 
int main()
{
 int major = 0;
 int minor = 0;
 int patch = 0;
 zmq_version( &major, &minor, &patch );
 std::wcout << "Current 0MQ version is " << major << '.' << minor << '.' << patch << '\n';
}
Copy to folder beside a.cpp from
C:\Repos\vcpkg\packages\zeromq_x64-windows\include
zmq.h
zmq_utils.h
C:\Repos\vcpkg\packages\zeromq_x64-windows\debug\lib\libzmq-mt-gd-4_3_2.lib
C:\Repos\vcpkg\packages\zeromq_x64-windows\lib\libzmq-mt-4_3_2.lib
C:\Repos\vcpkg\packages\zeromq_x64-windows\debug\bin\libzmq-mt-gd-4_3_2.dll
C:\Repos\vcpkg\packages\zeromq_x64-windows\bin\libzmq-mt-4_3_2.dll

Static ZeroMQ (Original full version)



https://joshuaburkholder.com/wordpress/2018/05/25/build-and-static-link-zeromq-on-windows/









Build and static link ZeroMQ on Windows


ZeroMQ ( http://zeromq.org and https://github.com/zeromq/libzmq ) is a library that allows code to communicate between threads, processes, or computers in just a few lines and uses simple, composable patterns (like publish-subscribe and broadcast).
In this post, we’ll build ZeroMQ on Windows as a static library (to take advantage of the “static linking exception” in its license: http://zeromq.org/area:licensing ) and then bake that static library into a simple Windows executable.  There are many posts around the web that show you how to do this … here’s one more:

Steps:

  1. Build Vcpkg ( https://github.com/Microsoft/vcpkg )
  2. Use vcpkg to build ZeroMQ ( vcpkg install zeromq:x64-windows-static )
  3. Build an executable that statically links ZeroMQ

Step 1: Build Vcpkg ( https://github.com/Microsoft/vcpkg )

Notes:
  • Vcpkg does not manage pre-built binaries (like NuGet or Homebrew)
  • Vcpkg manages source code and builds that source code on Windows, Linux, and MacOS.
  • At the time of this post, the documentation for Vcpkg was located here:
    https://docs.microsoft.com/en-us/cpp/vcpkg
In a Visual Studio 2017 developer command prompt (with Git installed), execute the following commands:
cd /d C:\
mkdir Repos
cd /d C:\Repos\
git clone https://github.com/Microsoft/vcpkg
cd /d C:\Repos\vcpkg\
bootstrap-vcpkg.bat
… now, C:\Repos\vcpkg\vcpkg.exe should exist.

Step 2: Use vcpkg to build ZeroMQ ( vcpkg install zeromq:x64-windows-static )

Note:
  • On purpose … to make things more explicit and more difficult in Step 3, we do not execute the following command:
vcpkg integrate install
Now that C:\Repos\vcpkg\vcpkg.exe exists, execute the following commands:
cd /d C:\Repos\vcpkg\
vcpkg install zeromq:x64-windows-static
… now, we should have the following:
  • ZeroMQ source code folder: C:\Repos\vcpkg\buildtrees\zeromq\src
  • ZeroMQ debug build folder: C:\Repos\vcpkg\buildtrees\zeromq\x64-windows-static-dbg
  • ZeroMQ release build folder: C:\Repos\vcpkg\buildtrees\zeromq\x64-windows-static-rel
  • ZeroMQ target folder: C:\Repos\vcpkg\packages\zeromq_x64-windows-static
  • ZeroMQ target include folder: C:\Repos\vcpkg\packages\zeromq_x64-windows-static\include
  • ZeroMQ target debug lib folder: C:\Repos\vcpkg\packages\zeromq_x64-windows-static\debug\lib
    • At the time of this post, the static library built was: libzmq-mt-sgd-4_3_1.lib
    • Note: The mt and d in libzmq-mt-sgd-4_3_1.lib means multi-threaded debug (requiring the debug executable in the next step to be compiled using /MTd)
  • ZeroMQ target release lib folder: C:\Repos\vcpkg\packages\zeromq_x64-windows-static\lib
    • At the time of this post, the static library built was: libzmq-mt-s-4_3_1.lib
    • Note: The mt in libzmq-mt-s-4_3_1.lib means multi-threaded (requiring the release executable in the next step to be compiled using /MT)

Step 3: Build an executable that statically links ZeroMQ

In Visual Studio 2017, do the following:
  • File / New / Project…



     
  • Add / New Item…

     
  • Paste the following code into Source.cpp:
    #include <zmq.h>
    #include <iostream>
     
    int main()
    {
     int major = 0;
     int minor = 0;
     int patch = 0;
     zmq_version( &major, &minor, &patch );
     std::wcout << "Current 0MQ version is " << major << '.' << minor << '.' << patch << '\n';
    }
  • Change the Solution Platform to x64:

     
  • Select the “ZeroMQ-Version” project, select Project / Properties, change the Configuration to “All Configurations“, select Configuration Properties / C/C++ / General, and then add the following include folder to “Additional Include Directories“:
    C:\Repos\vcpkg\packages\zeromq_x64-windows-static\include



     
  • Next, for “All Configurations“, select Configuration Properties / C/C++ / Preprocessor, and then add the following preprocessor definition to “Preprocessor Definitions“:
    ZMQ_STATIC

     
  • Next, change the Configuration to “Debug“, select Configuration Properties / C/C++ / Code Generation, and then change the “Runtime Library” to “Multi-threaded Debug (/MTd)“:



     
  • Next, change the Configuration to “Release“, select Configuration Properties / C/C++ / Code Generation, and then change the “Runtime Library” to “Multi-threaded (/MT)“:



     
  • Next, we’ll add the static libraries … and while we could break these up into separate lib folder and lib file entries, I’ll just use each lib’s full file path here.
  • First, switch the Configuration back to “Debug“, select Configuration Properties / Linker / Input, and then add the following entries to “Additional Dependencies“:
    C:\Repos\vcpkg\packages\zeromq_x64-windows-static\debug\lib\libzmq-mt-sgd-4_3_1.lib
    Ws2_32.lib
    Iphlpapi.lib



     
  • Second, switch the Configuration back to “Release“, select Configuration Properties / Linker / Input, and then add the following entries to “Additional Dependencies“:
    C:\Repos\vcpkg\packages\zeromq_x64-windows-static\lib\libzmq-mt-s-4_3_1.lib
    Ws2_32.lib
    Iphlpapi.lib



     
  • Build / Rebuild Solution:

     
  • Debug / Start Without Debugging:

     
Note:
  • When building for Debug, my Output window reads:
    1>------ Rebuild All started: Project: ZeroMQ-Version, Configuration: Debug x64 ------
    1>Source.cpp
    1>ZeroMQ-Version.vcxproj -> C:\Repos\ZeroMQ-Version\x64\Debug\ZeroMQ-Version.exe
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
  • When building for Release, my Output window reads:
    1>------ Rebuild All started: Project: ZeroMQ-Version, Configuration: Release x64 ------
    1>Source.cpp
    1>Generating code
    1>All 3752 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
    1>Finished generating code
    1>ZeroMQ-Version.vcxproj -> C:\Repos\ZeroMQ-Version\x64\Release\ZeroMQ-Version.exe
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Hope This Helps!
Tagged on: 

1 則留言:

  1. Jotmynotes: Static And Dynamic Link Zeromq On Windows For Visual Studio 2017 X64 >>>>> Download Now

    >>>>> Download Full

    Jotmynotes: Static And Dynamic Link Zeromq On Windows For Visual Studio 2017 X64 >>>>> Download LINK

    >>>>> Download Now

    Jotmynotes: Static And Dynamic Link Zeromq On Windows For Visual Studio 2017 X64 >>>>> Download Full

    >>>>> Download LINK

    回覆刪除

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...