使用Visual Studio 2017构建open62541 DLL [英] Build open62541 DLL with Visual Studio 2017

查看:190
本文介绍了使用Visual Studio 2017构建open62541 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想使用open62541 lib为OPC UA服务器编写UI。
输入的软件应读取文本文件并将数据通过服务器投射到已经可用的客户端上。



停留在需要编译dll文件以进一步在其中使用的阶段Windows窗体项目。



提到了一些信息,Davy Triponney使用Visual C ++ 2013对其进行了编译



获取批处理警告和构建错误:

 严重程度代码说明项目文件行抑制状态
警告C4005'CLOSESOCKET':宏重定义open62541 c:用户\scadaadmin\桌面\open62541-win64\open62541.c 39113
警告C4005'_Q_INVALIDATE':宏重定义open62541 c:\用户\scadaadmin\desktop\ open62541-win64\open62541.c 130
警告C4005'UA_atomic_sync':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 813
警告C4005 'UA_atomic_sync':宏重新定义open62541 c:\usersscadaadmin\desktop\open62541-win64\open62541.c 815
警告C4005'CLOSESOCKET':宏重新定义open62541 c:\users\scadaadmin \desktop\open62541-win64\open62541.c 35386
警告C4005'errno__':宏重新定义open62541 c:\users\sca daadmin\desktop\open62541-win64\open62541.c 35387
警告C4005'CLOSESOCKET':宏重新定义了open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39088
警告C4005'CLOSESOCKET':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39106
警告C4005'UA_sleep_ms':宏重新定义open62541 c: \user\scadaadmin\desktop\open62541-win64\open62541.c 39111
警告C4005'UA_sleep_ms':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\ \open62541.c 39127
警告C4005'UA_sleep_ms':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39130
警告C4005'WIN32_INT':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39135
警告C4005'OPTVAL_TYPE':宏重新定义open62541 c:\users\scadaadmin\desktop\ \open62541-赢64\open62541.c 39136
警告C4005'ERR_CONNECTION_PROGRESS':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39137
警告C4005'UA_fd_set ':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39167
警告C4005'UA_fd_isset':宏重新定义open62541 c:\users\scadaadmin\ desktop\open62541-win64\open62541.c 39168
警告C4005'errno__':宏重新定义open62541 c:\usersscadaadmin\desktop\open62541-win64\open62541.c 39176
警告C4005'errno__':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39181
警告C4005'INTERRUPTED':宏重新定义open62541 c:\users \scadaadmin\desktop\open62541-win64\open62541.c 39182
警告C4005'WOULDBLOCK':宏重新定义了open62541 c:\用户\scadaadmin\desktop\open62541-win64\open62541。 c 39183
警告C4005'再次':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 39184
警告C4005'ANSI_COLOR_RED':宏重新定义open62541 c:\ users\scadaadmin\desktop\open62541-win64\open62541.c 40158
警告C4005'ANSI_COLOR_GREEN':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541 .c 40159
警告C4005'ANSI_COLOR_YELLOW':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40160
警告C4005'ANSI_COLOR_BLUE':宏重新定义open62541 c:\\ users \\ scadaadmin \\ desktop \\ open62541-win64 \\ open62541.c 40161
警告C4005'ANSI_COLOR_MAGENTA':宏重新定义open62541 c:\\ users \\ scadaadmin\desktop\open62541 -win64\open62541.c 40162
警告C4005'ANSI_COLOR_CYAN':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40163
警告ing C4005'ANSI_COLOR_RESET':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40164
警告C4005'BEGIN_CRITSECT':宏重新定义open62541 c:\users\ \scadaadmin\desktop\open62541-win64\open62541.c 40709
警告C4005'END_CRITSECT':宏重新定义open62541 c:\users\scadaadmin\desktop\open62541-win64\open62541.c 40710
查找预编译的标头时,错误C1010文件意外结束。您是否忘记在源中添加 #include stdafx.h? 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模块六个


pip安装六个



构建MBEDTLS




  1. 下载资源库(Apache许可证)

https://tls.mbed.org/download


  1. 运行cmake来源



  cmake。 -DUSE_SHARED_MBEDTLS_LIBRARY = ON -D CMAKE_BUILD_TYPE =释放




  1. 使用Visual Studio打开 mbed TLS.sln(我正在使用Community 2015),并以发布模式生成所有内容


  2. 复制以下文件




    • libraries .lib从 library\Release到 Path\To\OpcUa_lib

    • binaries .dll从库\发布到 Path\To\OpcUa_bin

    • include中的 mbedtls文件夹到 Path\To\ pcOpcUa_include




建造OPEN62541




  1. 克隆open62541存储库以获取源(使用GitHub桌面或命令行)

https://github.com/open62541/open62541


  1. 在源代码中创建一个文件夹 build(例如C:\Users\Davy\Documents\GitHub\open62541\ \构建)


  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 =发布-DUA_LOGLEVEL = 100 




  1. 使用Visual Studio(社区2015)打开解决方案 build\open62541.sln,并添加 mbedcrypto.lib, mbedtls.lib和 mbedx509.lib作为项目 open62541 / lib / open62541




    • 右键单击 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和。在链接器中添加以下依赖项:open62541.lib,mbedcrypto.lib,mbedtls.lib,mbedx509.lib,Ws2_32.lib。我还必须在项目属性中指定平台Visual Studio 2013(v120)。


Hello community I would like to write UI for OPC UA server using open62541 lib. The input off software should read text file and cast data throe server to already available client.

Stuck at stage where need compile dll file for further using it in windows forms project.

There is some info mentioned that Davy Triponney compiled it with Visual C++ 2013 https://github.com/open62541/open62541/wiki/Using-open62541-from-C%23

But I have no luck with VS 2017.

There is sequence of my progress:

  • Already downloaded .h and .c windows 64 bit files from https://open62541.org/
  • Created Dynamic-Link Library(DLL) project.
  • Attached .h and .c files to project, selected 64 compiler:

Getting lot warnings and fault on build:

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   

The question is how property I can compile open62541 c code dll file with Visual Studio 2017 to able use it in a windows forms C# application as server?

解决方案

Since the project open62541 has been updated I suggest you take directly the current state of the sources. This way you will be able to better use the examples they provide. Here is the howto for building the project. Maybe it could be simpler but I encountered quite a lot of problems so I give you all the steps I did.


PREPARING THE ENVIRONMENT

  1. Install cmake (with the PATH update)

https://cmake.org/download/

  1. Install a recent version of python (with the PATH update)

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

  1. Reopen your session so that the new PATH variables are taken into account

  2. Install the python module "six"

pip install six

BUILDING MBEDTLS

  1. Download the sources of the library (apache license)

https://tls.mbed.org/download

  1. Run cmake in the sources

cmake . -DUSE_SHARED_MBEDTLS_LIBRARY=ON -D CMAKE_BUILD_TYPE=Release

  1. Open "mbed TLS.sln" with Visual Studio (I am using Community 2015) and generate everything in "Release" mode

  2. Copy the following files

    • libraries .lib from "library\Release" to "Path\To\OpcUa_lib"
    • binaries .dll from "library\Release" to "Path\To\OpcUa_bin"
    • the folder "mbedtls" in "include" to "Path\To\OpcUa_include"

BUILDING OPEN62541

  1. Clone the open62541 repository to get the sources (with GitHub desktop or command line)

https://github.com/open62541/open62541

  1. Create a folder "build" in the sources (for example C:\Users\Davy\Documents\GitHub\open62541\build)

  2. Open a terminal in the "build" folder and run cmake (adapt \path\To... first)

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. Open the solution "build\open62541.sln" with Visual Studio (Community 2015) and add "mbedcrypto.lib", "mbedtls.lib" and "mbedx509.lib" as resources for the linker in the project "open62541/lib/open62541"

    • right click on "open62541/lib/open62541", select "properties"
    • go to "Linker" => "General"
    • add "Path\To\OpcUa_lib" as additional directory for the dependencies
    • go to "Linker" => "Entry"
    • add three lines with "mbedcrypto.lib", "mbedtls.lib" and "mbedx509.lib" in "Additional dependencies"
  2. Generate "open62541/lib/open62541" in "Release" mode

  3. You can now use the following files

    • the library "build\bin\Release\open62541.lib"
    • the binary "build\bin\Release\open62541.dll"
    • the file "build\open62541.h"

INTEGRATION IN ANOTHER PROJECT

You will need to reference the amalgamated .h of open62541 and add these dependencies in the linker: open62541.lib, mbedcrypto.lib, mbedtls.lib, mbedx509.lib, Ws2_32.lib. I also had to specify the platform Visual Studio 2013 (v120) in the project properties.

这篇关于使用Visual Studio 2017构建open62541 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆