nanomsg.nng 在windows下的安装
這里需要說明 按照上述的方法 build的結(jié)果是一個(gè) nng.lib 這樣一個(gè)static library, 不是 shared library (dll)
同時(shí),你使用這個(gè)nng.lib 配合 nng.h 使用nng, 必然不能成功編譯, 報(bào)錯(cuò)類似:
Error LNK2019 unresolved external symbol __imp__nng_setopt referenced in function
關(guān)于為什么會有 __imp 前綴請查閱其他文檔。 這里發(fā)生錯(cuò)誤是因?yàn)?#xff0c;nng.h 默認(rèn)是配合 shared library (dll) 使用, 而不是 static library (lib)
但是默認(rèn)的 nng編譯卻生出來 static library
查看nng.h 的源文件:
注意到宏 NNG_STATIC_LIB 是控制到底使用 static library 還是 shared library 的開關(guān)
所以:
1.使用 static library, 必須定義 NNG_STATIC_LIB
2.使用 shared library, 必須定義 NNG_SHARED_LIB
順便說一句,在我的測試中, NNG_STATIC_LIB 必須在工程中的預(yù)定義宏中設(shè)置,在其他地方實(shí)現(xiàn)無效。
這個(gè)問題 nng 上的一個(gè) issue有討論:
https://github.com/nanomsg/nng/issues/550
再回到最前面,我們?nèi)绾卧诿钚兄幸骳make 創(chuàng)建 shared library, 而不是 static library呢?
cmake -DBUILD_SHARED_LIBS=ON -G “Ninja” …
參數(shù) BUILD_SHARED_LIBS 顯示設(shè)為 ON
前綴 -D 表示定義
如此編譯出的nng就是 shared lib (dll) 而不是 static lib (lib) 了。
以上我們講解了如何編譯 x86/x64 dll/lib nng的方法
希望對你有幫助。
總結(jié)
以上是生活随笔為你收集整理的nanomsg.nng 在windows下的安装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ★★★★★ Visual Studio
- 下一篇: Unity 工具栏功能介绍