如何启用 DRAFT API for zeromq/cppzmq 以使用 vcpkg 在 Windows 上构建?

How to enable DRAFT API for zeromq/cppzmq to build on Windows with vcpkg?

使用 vcpkg,在我为 zeromqcppzmq 启用 ZMQ_BUILD_DRAFT_API 之后。构建失败并出现以下错误

1>------ Build started: Project: myproj, Configuration: Debug x64 ------
1>my1.cpp
1>my2.cpp
1>my3.cpp
1>my4.cpp
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_new referenced in function "public: __cdecl zmq::poller_t<unsigned __int64>::poller_t<unsigned __int64>(void)" (??0?$poller_t@_K@zmq@@QEAA@XZ)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_destroy referenced in function "public: void __cdecl zmq::poller_t<unsigned __int64>::destroy_poller_t::operator()(void *)" (??Rdestroy_poller_t@?$poller_t@_K@zmq@@QEAAXPEAX@Z)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_add referenced in function "private: void __cdecl zmq::poller_t<unsigned __int64>::add_impl(class zmq::socket_ref,enum zmq::event_flags,unsigned __int64 *)" (?add_impl@?$poller_t@_K@zmq@@AEAAXVsocket_ref@2@W4event_flags@2@PEA_K@Z)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_remove referenced in function "public: void __cdecl zmq::poller_t<unsigned __int64>::remove(class zmq::socket_ref)" (?remove@?$poller_t@_K@zmq@@QEAAXVsocket_ref@2@@Z)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_wait_all referenced in function "public: unsigned __int64 __cdecl zmq::poller_t<unsigned __int64>::wait_all(class std::vector<struct zmq::poller_event<unsigned __int64>,class std::allocator<struct zmq::poller_event<unsigned __int64> > > &,class std::chrono::duration<__int64,struct std::ratio<1,1000> >)" (?wait_all@?$poller_t@_K@zmq@@QEAA_KAEAV?$vector@U?$poller_event@_K@zmq@@V?$allocator@U?$poller_event@_K@zmq@@@std@@@std@@V?$duration@_JU?$ratio@[=13=][=13=]DOI@@std@@@chrono@4@@Z)
1>G:\build\x64\Debug\myproj.exe : fatal error LNK1120: 5 unresolved externals
1>Done building project "myproj.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


这是我的 portfile.cmake for zeromq

include(vcpkg_common_functions)

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO zeromq/libzmq
    REF 8d34332ff2301607df0fc9971a2fbe903c0feb7c
    SHA512 8b3a9b6c4e5236353672b6deb64c94ac79deb116962405f01fe36e2fd8ddc48ec65d88ffc06746ce2e13c93eaeb04e4ba73de8f9d6f2a57a73111765d5ba8ad7
    HEAD_REF master
)

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)

vcpkg_check_features(
    OUT_FEATURE_OPTIONS FEATURE_OPTIONS
    FEATURES
        sodium WITH_LIBSODIUM        
    INVERTED_FEATURES
        websockets-sha1 DISABLE_WS
)

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
    PREFER_NINJA
    OPTIONS
        -DZMQ_BUILD_TESTS=OFF
        -DPOLLER=select
        -DBUILD_STATIC=${BUILD_STATIC}
        -DBUILD_SHARED=${BUILD_SHARED}
        -DWITH_PERF_TOOL=OFF
        -DWITH_DOCS=OFF
        -DWITH_NSS=OFF
        -DZMQ_BUILD_DRAFT_API=ON
        ${FEATURE_OPTIONS}
    OPTIONS_DEBUG
        "-DCMAKE_PDB_OUTPUT_DIRECTORY=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
)

vcpkg_install_cmake()

vcpkg_copy_pdbs()

if(EXISTS ${CURRENT_PACKAGES_DIR}/CMake)
    vcpkg_fixup_cmake_targets(CONFIG_PATH CMake)
endif()
if(EXISTS ${CURRENT_PACKAGES_DIR}/share/cmake/ZeroMQ)
    vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/ZeroMQ)
endif()

file(COPY
    ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake
    DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
    vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/include/zmq.h
        "defined ZMQ_STATIC"
        "1 //defined ZMQ_STATIC"
    )
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
    file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
endif()

# Handle copyright
file(RENAME ${CURRENT_PACKAGES_DIR}/share/zmq/COPYING.LESSER.txt ${CURRENT_PACKAGES_DIR}/share/zeromq/copyright)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include ${CURRENT_PACKAGES_DIR}/debug/share ${CURRENT_PACKAGES_DIR}/share/zmq)

# CMake integration test
vcpkg_test_cmake(PACKAGE_NAME ZeroMQ)

这里是 cppzmq

include(vcpkg_common_functions)

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO zeromq/cppzmq
    REF v4.4.1
    SHA512 5178a24413e44a6d99e57db7c9859c72279304272baa0e1fb810174cdf592cb567cab98428ef3ab611042bdf4bc506867421662409d1f0d82c233cb83ebdb801
    HEAD_REF master
)

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
    PREFER_NINJA
    OPTIONS 
        -DCPPZMQ_BUILD_TESTS=OFF
        -DZMQ_BUILD_DRAFT_API=ON
)



vcpkg_install_cmake()

vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/cppzmq)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug ${CURRENT_PACKAGES_DIR}/share/cppzmq/libzmq-pkg-config)

# Handle copyright
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/cppzmq)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/cppzmq/LICENSE ${CURRENT_PACKAGES_DIR}/share/cppzmq/copyright)

DUMPBIN导出符号的输出显示相关符号缺失

Microsoft (R) COFF/PE Dumper Version 14.16.27032.1
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file E:\_dev\vcpkg\installed\x64-windows\lib\libzmq-mt-4_3_3.lib

File Type: LIBRARY

COFF SYMBOL TABLE
000 01016998 ABS    notype       Static       | @comp.id
001 00000000 SECT2  notype       External     | __IMPORT_DESCRIPTOR_libzmq-mt-4_3_3
002 C0000040 SECT2  notype       Section      | .idata
003 00000000 SECT3  notype       Static       | .idata
004 C0000040 UNDEF  notype       Section      | .idata
005 C0000040 UNDEF  notype       Section      | .idata
006 00000000 UNDEF  notype       External     | __NULL_IMPORT_DESCRIPTOR
007 00000000 UNDEF  notype       External     | libzmq-mt-4_3_3_NULL_THUNK_DATA

String Table Size = 0x62 bytes

COFF SYMBOL TABLE
000 01016998 ABS    notype       Static       | @comp.id
001 00000000 SECT2  notype       External     | __NULL_IMPORT_DESCRIPTOR

String Table Size = 0x1D bytes

COFF SYMBOL TABLE
000 01016998 ABS    notype       Static       | @comp.id
001 00000000 SECT2  notype       External     | libzmq-mt-4_3_3_NULL_THUNK_DATA

String Table Size = 0x25 bytes

     Exports

       ordinal    name

                  zmq_atomic_counter_dec
                  zmq_atomic_counter_destroy
                  zmq_atomic_counter_inc
                  zmq_atomic_counter_new
                  zmq_atomic_counter_set
                  zmq_atomic_counter_value
                  zmq_bind
                  zmq_close
                  zmq_connect
                  zmq_ctx_destroy
                  zmq_ctx_get
                  zmq_ctx_new
                  zmq_ctx_set
                  zmq_ctx_shutdown
                  zmq_ctx_term
                  zmq_curve_keypair
                  zmq_curve_public
                  zmq_device
                  zmq_disconnect
                  zmq_errno
                  zmq_getsockopt
                  zmq_has
                  zmq_init
                  zmq_msg_close
                  zmq_msg_copy
                  zmq_msg_data
                  zmq_msg_get
                  zmq_msg_gets
                  zmq_msg_init
                  zmq_msg_init_data
                  zmq_msg_init_size
                  zmq_msg_more
                  zmq_msg_move
                  zmq_msg_recv
                  zmq_msg_send
                  zmq_msg_set
                  zmq_msg_size
                  zmq_poll
                  zmq_proxy
                  zmq_proxy_steerable
                  zmq_recv
                  zmq_recviov
                  zmq_recvmsg
                  zmq_send
                  zmq_send_const
                  zmq_sendiov
                  zmq_sendmsg
                  zmq_setsockopt
                  zmq_sleep
                  zmq_socket
                  zmq_socket_monitor
                  zmq_stopwatch_intermediate
                  zmq_stopwatch_start
                  zmq_stopwatch_stop
                  zmq_strerror
                  zmq_term
                  zmq_threadclose
                  zmq_threadstart
                  zmq_timers_add
                  zmq_timers_cancel
                  zmq_timers_destroy
                  zmq_timers_execute
                  zmq_timers_new
                  zmq_timers_reset
                  zmq_timers_set_interval
                  zmq_timers_timeout
                  zmq_unbind
                  zmq_version
                  zmq_z85_decode
                  zmq_z85_encode

  Summary

          DB .debug$S
          14 .idata
          14 .idata
           8 .idata
           8 .idata
          14 .idata

如何使用 vcpkg 启用 DRAFT API?

已通过 the help from the 0MQ github community 解决: 我用错了开关。

It must be -DENABLE_DRAFTS=ON here. ZMQ_BUILD_DRAFT_API is the preprocessor definition, but the CMake option is called ENABLE_DRAFTS.

此外,预处理器 ZMQ_BUILD_DRAFT_API 仍必须在 VS 项目中定义。

我希望这样的信息更容易查找。

要使用当前版本的草稿 api 支持构建它,它在命令行上使用功能标志:

vcpkg.exe install zeromq[draft]:x64-windows zeromq[draft]:x86-windows cppzmq[draft]:x64-windows cppzmq[draft]:x86-windows