簡體   English   中英

使用Visual Studio 2017構建open62541 DLL

[英]Build open62541 DLL with Visual Studio 2017

您好社區,我想使用open62541 lib為OPC UA服務器編寫UI。 輸入輸出軟件應讀取文本文件,然后將數據投放到已經可用的客戶端。

停留在需要編譯dll文件以便在Windows窗體項目中進一步使用它的階段。

有一些信息提到Davy Triponney使用Visual C ++ 2013對其進行了編譯https://github.com/open62541/open62541/wiki/Using-open62541-from-C%23

但是我對VS 2017沒有運氣。

我的進度是有順序的:

  • 已經從https://open62541.org/下載了.h和.c Windows 64位文件
  • 創建了動態鏈接庫(DLL)項目。
  • 將.h和.c文件附加到項目中,選擇64個編譯器:

項目

在構建時收到很多警告和錯誤:

Severity    Code    Description Project File    Line    Suppression State
Warning C4005   'CLOSESOCKET': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39113   
Warning C4005   '_Q_INVALIDATE': macro redefinition open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 130 
Warning C4005   'UA_atomic_sync': macro redefinition    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 813 
Warning C4005   'UA_atomic_sync': macro redefinition    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 815 
Warning C4005   'CLOSESOCKET': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 35386   
Warning C4005   'errno__': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 35387   
Warning C4005   'CLOSESOCKET': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39088   
Warning C4005   'CLOSESOCKET': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39106   
Warning C4005   'UA_sleep_ms': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39111   
Warning C4005   'UA_sleep_ms': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39127   
Warning C4005   'UA_sleep_ms': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39130   
Warning C4005   'WIN32_INT': macro redefinition open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39135   
Warning C4005   'OPTVAL_TYPE': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39136   
Warning C4005   'ERR_CONNECTION_PROGRESS': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39137   
Warning C4005   'UA_fd_set': macro redefinition open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39167   
Warning C4005   'UA_fd_isset': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39168   
Warning C4005   'errno__': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39176   
Warning C4005   'errno__': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39181   
Warning C4005   'INTERRUPTED': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39182   
Warning C4005   'WOULDBLOCK': macro redefinition    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39183   
Warning C4005   'AGAIN': macro redefinition open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39184   
Warning C4005   'ANSI_COLOR_RED': macro redefinition    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40158   
Warning C4005   'ANSI_COLOR_GREEN': macro redefinition  open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40159   
Warning C4005   'ANSI_COLOR_YELLOW': macro redefinition open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40160   
Warning C4005   'ANSI_COLOR_BLUE': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40161   
Warning C4005   'ANSI_COLOR_MAGENTA': macro redefinition    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40162   
Warning C4005   'ANSI_COLOR_CYAN': macro redefinition   open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40163   
Warning C4005   'ANSI_COLOR_RESET': macro redefinition  open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40164   
Warning C4005   'BEGIN_CRITSECT': macro redefinition    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40709   
Warning C4005   'END_CRITSECT': macro redefinition  open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40710   
Error   C1010   unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?    open62541   c:\users\scadaadmin\desktop\open62541-win64\open62541.c 43979   

問題是如何使用Visual Studio 2017編譯open62541 C代碼dll文件以使其能夠在Windows窗體C#應用程序中用作服務器的屬性?

由於項目open62541已更新,我建議您直接獲取源的當前狀態。 這樣,您將可以更好地使用它們提供的示例。 這是構建項目的方法。 也許它可能更簡單,但是我遇到了很多問題,因此我將為您提供所有我執行的步驟。


准備環境

  1. 安裝cmake(使用PATH更新)

https://cmake.org/download/

  1. 安裝最新版本的python(使用PATH更新)

https://www.python.org/downloads/

  1. 重新打開您的會話,以便考慮新的PATH變量

  2. 安裝python模塊“六”

點安裝六

建立MBEDTLS

  1. 下載庫的資源(apache許可證)

https://tls.mbed.org/download

  1. 在源代碼中運行cmake
cmake . -DUSE_SHARED_MBEDTLS_LIBRARY=ON -D CMAKE_BUILD_TYPE=Release
  1. 使用Visual Studio打開“ mbed TLS.sln”(我正在使用Community 2015),並以“發布”模式生成所有內容

  2. 復制以下文件

    • 庫.lib從“ library \\ Release”到“ Path \\ To \\ OpcUa_lib”
    • 二進制文件.dll從“庫\\發布”到“ Path \\ To \\ OpcUa_bin”
    • “包含”中的文件夾“ mbedtls”到“ Path \\ To \\ OpcUa_include”

建OPEN62541

  1. 克隆open62541存儲庫以獲取源(使用GitHub桌面或命令行)

https://github.com/open62541/open62541

  1. 在源代碼中創建一個文件夾“ build”(例如C:\\ Users \\ Davy \\ Documents \\ GitHub \\ open62541 \\ build)

  2. 在“ build”文件夾中打開一個終端,然后運行cmake(首先適應\\ path \\ To ...)

cmake .. -G "Visual Studio 14 2015" -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_AMALGAMATION=ON -DMBEDTLS_INCLUDE_DIRS="Path\To\OpcUa_include" -DMBEDTLS_LIBRARY="Path\To\OpcUa_lib" -DMBEDX509_LIBRARY="Path\To\OpcUa_lib" -DMBEDCRYPTO_LIBRARY="Path\To\OpcUa_lib" -DBUILD_SHARED_LIBS=ON -D CMAKE_BUILD_TYPE=Release -DUA_LOGLEVEL=100
  1. 使用Visual Studio(社區2015)打開解決方案“ build \\ open62541.sln”,並在項目“ open62541 / lib / open62541”中添加“ mbedcrypto.lib”,“ mbedtls.lib”和“ mbedx509.lib”作為鏈接器的資源。 “

    • 右鍵單擊“ open62541 / lib / open62541”,選擇“屬性”
    • 轉到“鏈接器” =>“常規”
    • 添加“ Path \\ To \\ OpcUa_lib”作為依賴項的其他目錄
    • 轉到“鏈接器” =>“條目”
    • 在“其他依賴項”中添加帶有“ mbedcrypto.lib”,“ mbedtls.lib”和“ mbedx509.lib”的三行
  2. 在“發布”模式下生成“ open62541 / lib / open62541”

  3. 您現在可以使用以下文件

    • 庫“ build \\ bin \\ Release \\ open62541.lib”
    • 二進制文件“ build \\ bin \\ Release \\ open62541.dll”
    • 文件“ build \\ open62541.h”

整合到另一個項目中

您將需要引用open62541的合並后的.h並將這些依賴項添加到鏈接器中:open62541.lib,mbedcrypto.lib,mbedtls.lib,mbedx509.lib,Ws2_32.lib。 我還必須在項目屬性中指定平台Visual Studio 2013(v120)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM