日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

nanomsg.nng 在windows下的编译

發布時間:2024/1/1 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nanomsg.nng 在windows下的编译 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 需要 cmake 版本號大于等于3.1, 個人使用了Visual Studio 的 Native tools command prompt (分為x86, x64 分別用于Build各自構架的nng)
  • ?github源 https://github.com/nanomsg/nng 下載壓縮包解壓縮
  • 進入文件夾按照指導輸入:
  • mkdir buildx64
    cd buildx64
    cmake -G “Ninja” …
    ninja
    ninja test
    ninja install (這一步不要也可, 因為第6步已經生成了相應的文件在buildx64目錄中)

    這里需要說明 按照上述的方法 build的結果是一個 nng.lib 這樣一個static library, 不是 shared library (dll)
    同時,你使用這個nng.lib 配合 nng.h 使用nng, 必然不能成功編譯, 報錯類似:
    Error LNK2019 unresolved external symbol __imp__nng_setopt referenced in function
    關于為什么會有 __imp 前綴請查閱其他文檔。 這里發生錯誤是因為,nng.h 默認是配合 shared library (dll) 使用, 而不是 static library (lib)
    但是默認的 nng編譯卻生出來 static library
    查看nng.h 的源文件:

    // NNG_DECL is used on declarations to deal with scope. // For building Windows DLLs, it should be the appropriate __declspec(). // For shared libraries with platforms that support hidden visibility, // it should evaluate to __attribute__((visibility("default"))). #ifndef NNG_DECL #if defined(_WIN32) && !defined(NNG_STATIC_LIB) #if defined(NNG_SHARED_LIB) #define NNG_DECL __declspec(dllexport) #else #define NNG_DECL __declspec(dllimport) #endif // NNG_SHARED_LIB #else #if defined(NNG_SHARED_LIB) && defined(NNG_HIDDEN_VISIBILITY) #define NNG_DECL __attribute__((visibility("default"))) #else #define NNG_DECL extern #endif #endif // _WIN32 && !NNG_STATIC_LIB #endif // NNG_DECL


    注意到宏 NNG_STATIC_LIB 是控制到底使用 static library 還是 shared library 的開關
    所以:
    1.使用 static library, 必須定義 NNG_STATIC_LIB
    2.使用 shared library, 必須定義 NNG_SHARED_LIB
    順便說一句,在我的測試中, NNG_STATIC_LIB 必須在工程中的預定義宏中設置,在其他地方實現無效。
    這個問題 nng 上的一個 issue有討論:
    https://github.com/nanomsg/nng/issues/550

    再回到最前面,我們如何在命令行中要求cmake 創建 shared library, 而不是 static library呢?

    cmake -DBUILD_SHARED_LIBS=ON -G “Ninja” …

    參數 BUILD_SHARED_LIBS 顯示設為 ON
    前綴 -D 表示定義
    如此編譯出的nng就是 shared lib (dll) 而不是 static lib (lib) 了。

    以上我們講解了如何編譯 x86/x64 dll/lib nng的方法
    希望對你有幫助。

    總結

    以上是生活随笔為你收集整理的nanomsg.nng 在windows下的编译的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。