ubuntu1604下交叉编译open62541

 

1 下载源码

    git clone https://github.com/open62541/open62541.git

  安装依赖的软件包

# enable additional features
sudo apt-get install cmake-curses-gui # for the ccmake graphical interface
sudo apt-get install libmbedtls-dev # for encryption support
sudo apt-get install check libsubunit-dev # for unit tests
sudo apt-get install python-sphinx graphviz # for documentation generation
sudo apt-get install python-sphinx-rtd-theme # documentation style

2 创建build目录

    在源码根目录下新建build目录,并进入build目录

3 设置环境变量

    export CC=arm-linux-gnueabihf-gcc

    export CXX=arm-linux-gnueabihf-g++

4 编译

cd build

# cmake ..

# cmake .. -DBUILD_SHARED_LIBS=ON   # 编译成动态库

cmake .. -DUA_ENABLE_AMALGAMATION=ON    
 

make

这里解释下cmake的命令行中的UA_ENABLE_AMALGAMATION选项,这是open62541的CMakeLists.txt提供的选项,专门用于生成single distribution版本的open62541,即open62541.c 和 open62541.h文件,方便用于集成到其它程序里。在bin目录下生成的是open62541的静态库,可以用于和别的程序进行链接。

引用自:https://blog.csdn.net/qq_33406883/article/details/106421787?utm_medium=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase

5 编译成功

[ 86%] Building C object CMakeFiles/open62541-plugins.dir/plugins/crypto/ua_pki_none.c.o
[ 88%] Building C object CMakeFiles/open62541-plugins.dir/plugins/crypto/ua_securitypolicy_none.c.o
[ 88%] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_log_syslog.c.o
[ 90%] Building C object CMakeFiles/open62541-plugins.dir/arch/posix/ua_clock.c.o
[ 92%] Building C object CMakeFiles/open62541-plugins.dir/arch/posix/ua_architecture_functions.c.o
[ 94%] Building C object CMakeFiles/open62541-plugins.dir/arch/network_tcp.c.o
[ 98%] Built target open62541-plugins
Scanning dependencies of target open62541
[100%] Linking C static library bin/libopen62541.a
[100%] Built target open62541

编译后的库在build/bin/下面

$ ls bin/
libopen62541.a
并且在build目录下有:open62541.c open62541.h

 

6 测试

serv.c

// server.c                                                                                                                                                             
                                                                                                                                         
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.                                                          
 * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */                                                        
#include "open62541.h"                                                                                                                   
#include <signal.h>                                                                                                                      
#include <stdlib.h>                                                                                                                      
                                                                                                                                         
UA_Boolean running = true;                                                                                                               
                                                                                                                                         
static void stopHandler(int sign) {                                                                                                      
    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");                                                                
    running = false;                                                                                                                     
}                                                                                                                                        
                                                                                                                                         
int main(void)                                                                                                                           
{                                                                                                                                        
    signal(SIGINT, stopHandler);                                                                                                         
    signal(SIGTERM, stopHandler);                                                                                                        
    UA_Server *server = UA_Server_new();                                                                                                 
    UA_ServerConfig_setDefault(UA_Server_getConfig(server));                                                                             
    UA_StatusCode retval = UA_Server_run(server, &running);                                                                              
    UA_Server_delete(server);                                                                                                            
    return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;                                                                   
} 

client.c

// client.c,功能主要是从server那里获取时间                                                                                                                             
                                                                                                                                         
#include <stdlib.h>                                                                                                                      
#include "open62541.h"                                                                                                                   
int main(void)                                                                                                                           
{                                                                                                                                        
    UA_Client *client = UA_Client_new();                                                                                                 
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));                                                                             
    UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");                                                        
    if(retval != UA_STATUSCODE_GOOD) {                                                                                                   
        UA_Client_delete(client);                                                                                                        
        return (int)retval;                                                                                                              
    }                                                                                                                                    
                                                                                                                                         
    /* Read the value attribute of the node. UA_Client_readValueAttribute is a                                                           
    * wrapper for the raw read service available as UA_Client_Service_read. */                                                           
    UA_Variant value; /* Variants can hold scalar values and arrays of any type */                                                       
    UA_Variant_init(&value);                                                                                                             
                                                                                                                                         
    /* NodeId of the variable holding the current time */                                                                                
    const UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);                                             
    retval = UA_Client_readValueAttribute(client, nodeId, &value);                                                                       
                                                                                                                                         
    if(retval == UA_STATUSCODE_GOOD && UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_DATETIME]))                                   
    {                                                                                                                                    
        UA_DateTime raw_date = *(UA_DateTime *) value.data;                                                                              
        UA_DateTimeStruct dts = UA_DateTime_toStruct(raw_date);                                                                          
        UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "date is: %u-%u-%u %u:%u:%u.%03u\n",                                         
            dts.day, dts.month, dts.year, dts.hour, dts.min, dts.sec, dts.milliSec);                                                     
    }                                                                                                                                    
                                                                                                                                         
    /* Clean up */                                                                                                                       
    UA_Variant_clear(&value);                                                                                                            
    UA_Client_delete(client); /* Disconnects the client internally */                    

return EXIT_SUCCESS;                                                        
}                       

把上面编译的open62541.c  open62541.h和这两个测试代码放在一个目录下

$ ls
  client.c    open62541.c  open62541.h  server.c

编译:

$ arm-linux-gnueabihf-gcc -std=c99 open62541.c client.c -o client

$ arm-linux-gnueabihf-gcc -std=c99 open62541.c server.c.c -o server

运行:

把serv和client放到目标机器上:

# ./server 
[2020-10-22 15:08:54.667 (UTC+0800)] warn/server	AccessControl: Unconfigured AccessControl. Users have all permissions.
[2020-10-22 15:08:54.668 (UTC+0800)] info/server	AccessControl: Anonymous login is enabled
[2020-10-22 15:08:54.669 (UTC+0800)] warn/server	Username/Password configured, but no encrypting SecurityPolicy. This can leak credentials on the network.
[2020-10-22 15:08:54.670 (UTC+0800)] warn/userland	AcceptAll Certificate Verification. Any remote certificate will be accepted.
[2020-10-22 15:08:54.672 (UTC+0800)] info/network	TCP network layer listening on opc.tcp://imx6ull14x14evk:4840/
[2020-10-22 15:09:07.601 (UTC+0800)] info/network	Connection 5 | New connection over TCP from ::1
[2020-10-22 15:09:07.603 (UTC+0800)] info/channel	Connection 5 | SecureChannel 1 | SecureChannel opened with SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None and a revised lifetime of 600.00s
[2020-10-22 15:09:07.609 (UTC+0800)] info/channel	Connection 5 | SecureChannel 1 | Session 5f208920-4bab-1eeb-c8ec-1e0143c4fc3f created
[2020-10-22 15:09:07.618 (UTC+0800)] info/channel	Connection 5 | SecureChannel 1 | CloseSecureChannel
[2020-10-22 15:09:07.618 (UTC+0800)] info/network	Connection 5 | Closed

 

# ./client
[2020-10-22 15:09:07.586 (UTC+0800)] warn/userland	AcceptAll Certificate Verification. Any remote certificate will be accepted.
[2020-10-22 15:09:07.604 (UTC+0800)] info/channel	Connection 3 | SecureChannel 1 | SecureChannel opened with SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None and a revised lifetime of 600.00s
[2020-10-22 15:09:07.605 (UTC+0800)] info/client	Client Status: ChannelState: Open, SessionState: Closed, ConnectStatus: Good
[2020-10-22 15:09:07.607 (UTC+0800)] info/client	Selected Endpoint opc.tcp://localhost:4840 with SecurityMode None and SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None
[2020-10-22 15:09:07.608 (UTC+0800)] info/client	Selected UserTokenPolicy open62541-anonymous-policy with UserTokenType Anonymous and SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None
[2020-10-22 15:09:07.610 (UTC+0800)] info/client	Client Status: ChannelState: Open, SessionState: Created, ConnectStatus: Good
[2020-10-22 15:09:07.612 (UTC+0800)] info/client	Client Status: ChannelState: Open, SessionState: Activated, ConnectStatus: Good
[2020-10-22 15:09:07.613 (UTC+0800)] info/userland	date is: 22-10-2020 7:9:7.613

[2020-10-22 15:09:07.620 (UTC+0800)] info/client	Client Status: ChannelState: Closed, SessionState: Closed, ConnectStatus: Good
root@imx6ull14x14evk:/data/vpnclient# 

可以 看到client已经获取到了时间

 

出现的问题

  1. cmake时报错:

The C compiler
  "/home/sundh/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin/arm-linux-gnueabihf-gcc"
  is not able to compile a simple test program.
  ...略...

arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-m32’

...略...

解决办法:修改代码根目录下的CMakeLists.txt  把"-m32"部分的代码屏蔽掉

    # if(UA_FORCE_32BIT)                                                            
    #   string(FIND "${CMAKE_C_FLAGS}" "-m32" m32_already_set)                                                                                                          
    #   if(m32_already_set EQUAL -1)                                                
    #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")                                
    #   endif()                                                                     
    #   unset(flag_supported CACHE)                                                 
    # endif()  

参考说明:

https://github.com/open62541/open62541/blob/master/doc/building.rst

https://blog.csdn.net/qq_33406883/article/details/106421787?utm_medium=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. yes QML delegate model ..................... yes Qt Quick: Direct3D 12 ............................ no AnimatedImage item ..................... yes Canvas item ............................ yes Support for Qt Quick Designer .......... yes Flipable item .......................... yes GridView item .......................... yes ListView item .......................... yes TableView item ......................... yes Path support ........................... yes PathView item .......................... yes Positioner items ....................... yes Repeater item .......................... yes ShaderEffect item ...................... yes Sprite item ............................ yes Qt Scxml: ECMAScript data model for QtScxml ...... yes Qt Gamepad: SDL2 ................................... no Qt 3D: Assimp ................................. yes System Assimp .......................... no Output Qt3D Job traces ................. no Output Qt3D GL traces .................. no Use SSE2 instructions .................. no Use AVX2 instructions .................. no Aspects: Render aspect ........................ yes Input aspect ......................... yes Logic aspect ......................... yes Animation aspect ..................... yes Extras aspect ........................ yes Qt 3D Renderers: OpenGL Renderer ........................ yes Qt 3D GeometryLoaders: Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth API (desktop & UWP) .... no Qt Sensors: sensorfw ............................... no Qt Quick Controls 2: Styles ................................. Default Fusion Imagine Material Universal Qt Quick Templates 2: Hover support .......................... yes Multi-touch support .................... yes Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc
要在Ubuntu上安装Qt6交叉编译,可以按照以下步骤进行操作: 1. 首先,确保已经安装了libgl库,可以使用以下命令来安装: ``` sudo apt-get install libgl1-mesa-dev ``` 这样可以解决在执行Qt时出现“can't not find -lGL”的问题。 2. 下载并安装Qt6的开源版本。可以从Qt官方网站上下载适合您的Ubuntu版本的安装包。然后,在终端中导航到下载的安装包所在的目录,并运行以下命令来安装Qt6: ``` sudo ./qt-opensource-linux-x64-5.11.1.run ``` 这会启动Qt安装程序,并按照提示进行安装。 3. 安装完成后,您可以在Ubuntu的应用程序菜单中找到Qt。点击左下角的图标,然后搜索Qt即可找到Qt。 4. 接下来,需要设置交叉编译环境。首先,添加arm-linux-gnueabihf-gcc工具链。可以使用以下命令进行安装: ``` sudo apt-get install gcc-arm-linux-gnueabihf ``` 这将安装所需的交叉编译工具链。 5. 如果您的Ubuntu系统是arm64位的,则需要搭建一个aarch64环境。可以参考以下步骤进行操作: - 首先,确认您的Ubuntu系统是arm64位的,可以通过运行以下命令来检查: ``` uname -m ``` 如果结果是"aarch64",则您的系统架构已经是符合要求的。如果结果是"x86_64",则需要创建一个aarch64环境。 - 在虚拟机中安装一个aarch64的Ubuntu系统,或者在另一台arm64位的硬件设备上安装Ubuntu系统。 - 在该系统上搭建Qt交叉编译环境,确保Qt库和交叉编译工具匹配。 通过以上步骤,您就可以在Ubuntu上成功安装Qt6交叉编译环境了。请根据您的实际情况选择是否需要搭建aarch64环境。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [ubuntu搭建qt交叉编译环境](https://blog.csdn.net/L1643319918/article/details/125644934)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Ubuntu20.04配置aarch64的Qt6环境(亲测有效)](https://blog.csdn.net/qq_63986699/article/details/127731136)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值