ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

3种方法在macOS上构建SerialPlot:解决Qt跨平台部署的完整指南

3种方法在macOS上构建SerialPlot:解决Qt跨平台部署的完整指南 3种方法在macOS上构建SerialPlot解决Qt跨平台部署的完整指南【免费下载链接】serialplotSmall and simple software for plotting data from serial port in realtime.项目地址: https://gitcode.com/gh_mirrors/se/serialplotSerialPlot是一款基于Qt框架开发的实时串口数据可视化工具能够从串口读取数据并以波形图形式实时展示支持二进制和ASCII格式的数据解析。对于需要在macOS平台上进行嵌入式开发或传感器数据分析的开发者来说SerialPlot是一个非常有用的工具。本文将详细介绍在macOS上构建SerialPlot的三种不同方法帮助您解决跨平台部署中的常见问题。 为什么macOS上的构建会如此棘手在macOS上构建SerialPlot主要面临两个核心挑战Qt框架的跨平台适配和QWT库的依赖管理。虽然Qt本身支持macOS但SerialPlot使用的QWT绘图库在macOS上的部署需要特别注意动态库路径和构建选项。上图展示了SerialPlot在macOS上的实际运行效果可以看到清晰的实时数据波形显示和完整的串口配置界面。这正是我们想要在macOS上实现的目标。 方法一使用Homebrew构建推荐给macOS新手这是最简单直接的方法适合希望快速上手而不想深入配置的开发者。步骤1安装必要的依赖# 安装Homebrew如果尚未安装 /bin/bash -c $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) # 安装Qt6和QWT brew install qt6 brew install qwt # 安装其他构建工具 brew install cmake git pkg-config步骤2配置Qt环境变量# 将Qt6添加到PATH环境变量 echo export PATH/opt/homebrew/opt/qt6/bin:$PATH ~/.zshrc source ~/.zshrc # 验证Qt安装 qmake6 --version步骤3克隆并构建SerialPlot# 克隆项目 git clone https://gitcode.com/gh_mirrors/se/serialplot cd serialplot # 创建构建目录 mkdir build cd build # 配置CMake禁用自动构建QWT cmake .. -DBUILD_QWTOFF -DCMAKE_PREFIX_PATH$(brew --prefix qt6) # 开始构建 make -j$(sysctl -n hw.ncpu)步骤4修复动态库路径问题构建完成后您可能会遇到动态库加载错误。使用以下命令修复# 找到QWT库的实际位置 QWT_PATH$(brew --prefix qwt)/lib # 修复动态库路径 install_name_tool -add_rpath $QWT_PATH ./serialplot # 验证修复 otool -L ./serialplot | grep qwt 方法二手动构建QWT库适合需要自定义配置的开发者如果您需要特定版本的QWT库或希望完全控制构建过程这种方法更适合。步骤1手动下载和构建QWT 6.3.0# 下载QWT源码 cd ~/Downloads wget https://sourceforge.net/projects/qwt/files/qwt/6.3.0/qwt-6.3.0.tar.bz2 tar -xf qwt-6.3.0.tar.bz2 cd qwt-6.3.0 # 修改qwtconfig.pri文件以适配macOS sed -i s/QWT_CONFIG QwtDll/#/ qwtconfig.pri sed -i s/QWT_CONFIG QwtPolar/#/ qwtconfig.pri sed -i s/QWT_CONFIG QwtWidgets/#/ qwtconfig.pri # 构建QWT qmake6 qwt.pro make -j$(sysctl -n hw.ncpu) sudo make install步骤2构建SerialPlot并指定QWT路径cd serialplot mkdir build cd build # 指定QWT库的安装路径 cmake .. \ -DBUILD_QWTOFF \ -DQWT_ROOT/usr/local/qwt-6.3.0 \ -DCMAKE_PREFIX_PATH/opt/homebrew/opt/qt6 make -j$(sysctl -n hw.ncpu)步骤3创建macOS应用程序包# 创建.app应用程序包 mkdir -p SerialPlot.app/Contents/MacOS mkdir -p SerialPlot.app/Contents/Resources # 复制可执行文件和资源 cp serialplot SerialPlot.app/Contents/MacOS/ cp ../misc/serialplot.png SerialPlot.app/Contents/Resources/ # 创建Info.plist文件 cat SerialPlot.app/Contents/Info.plist EOF ?xml version1.0 encodingUTF-8? !DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd plist version1.0 dict keyCFBundleExecutable/key stringserialplot/string keyCFBundleIdentifier/key stringcom.serialplot.app/string keyCFBundleName/key stringSerialPlot/string keyCFBundleVersion/key string1.0/string /dict /plist EOF 方法三使用Conda环境适合科学计算和Python开发者如果您已经在使用Conda进行Python开发这种方法可以很好地集成到现有工作流中。步骤1创建并激活Conda环境# 创建新的Conda环境 conda create -n serialplot-env python3.9 # 激活环境 conda activate serialplot-env # 安装Qt和QWT conda install -c conda-forge qt qwt cmake make步骤2构建SerialPlot# 获取SerialPlot源码 git clone https://gitcode.com/gh_mirrors/se/serialplot cd serialplot # 创建构建目录 mkdir build cd build # 使用Conda环境中的Qt export QT_DIR$(conda info --base)/envs/serialplot-env export QWT_DIR$(conda info --base)/envs/serialplot-env cmake .. \ -DBUILD_QWTOFF \ -DCMAKE_PREFIX_PATH$QT_DIR;$QWT_DIR \ -DCMAKE_BUILD_TYPERelease make -j$(sysctl -n hw.ncpu)步骤3验证构建结果# 运行SerialPlot ./serialplot # 如果遇到动态库问题使用conda的fix工具 conda install -c conda-forge conda-forge::conda-build conda install -c conda-forge conda-forge::conda-verify️ 常见问题与解决方案问题1dyld: Library not loaded: rpath/libqwt.6.dylib解决方案# 查找libqwt.6.dylib的实际位置 find /opt/homebrew -name libqwt.6.dylib 2/dev/null # 添加运行时路径 install_name_tool -add_rpath /path/to/qwt/library ./serialplot # 或者复制库到应用程序包 mkdir -p SerialPlot.app/Contents/Frameworks cp /path/to/libqwt.6.dylib SerialPlot.app/Contents/Frameworks/问题2CMake找不到Qt6解决方案# 明确指定Qt6路径 cmake .. -DCMAKE_PREFIX_PATH/opt/homebrew/opt/qt6 # 或者设置环境变量 export Qt6_DIR$(brew --prefix qt6)/lib/cmake/Qt6问题3构建QWT时sed命令错误解决方案macOS的sed命令与Linux不同需要修改cmake/modules/BuildQwt.cmake文件# 将原来的sed命令修改为macOS兼容格式 PATCH_COMMAND sed -i -r -e s/QWT_CONFIG\\s*\\\\s*QwtDll/#/ SerialPlot在macOS上的核心功能验证成功构建后您可以在macOS上使用SerialPlot的所有核心功能实时数据可视化- 通过串口接收数据并实时绘制波形多通道支持- 同时显示多个传感器的数据数据格式解析- 支持二进制和ASCII格式命令发送功能- 向设备发送控制命令数据记录- 保存采集的数据到CSV文件在src/mainwindow.cpp中您可以看到SerialPlot的主界面实现包括菜单栏、绘图区域和配置面板的完整集成。 深入理解SerialPlot的架构设计SerialPlot采用模块化设计主要组件包括数据读取模块(src/abstractreader.cpp) - 处理不同格式的串口数据绘图引擎(src/plot.cpp) - 基于QWT的实时绘图系统用户界面(src/mainwindow.cpp) - Qt Widgets构建的图形界面数据管理(src/stream.cpp) - 处理数据流和缓冲区这种设计使得SerialPlot具有良好的可扩展性开发者可以根据需要添加新的数据格式或可视化功能。 下一步学习建议探索SerialPlot的插件系统- 了解如何添加自定义数据解析器研究QWT的高级功能- 学习更多绘图选项和交互功能集成到自动化测试流程- 将SerialPlot作为嵌入式系统测试的一部分贡献代码- 如果您解决了macOS特定的问题考虑向项目提交PR通过本文介绍的三种方法您应该能够在macOS上成功构建和运行SerialPlot。选择最适合您工作流程的方法开始享受实时串口数据可视化的便利吧【免费下载链接】serialplotSmall and simple software for plotting data from serial port in realtime.项目地址: https://gitcode.com/gh_mirrors/se/serialplot创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表