Compare commits

..

12 Commits

Author SHA1 Message Date
39fc9c4c7e 初次提交代码规范 2024-07-15 15:24:45 +08:00
a7ea4e35bd 创建Qt编译文章 2024-07-15 11:46:05 +08:00
439a8c9a80 由于Gitea的markdown目前不支持TOC自动目录语法,修改为使用Visual Studio Code插件【Markdown All in One】自动生成目录,使用方法为(注意得先安装该插件):
01. 将光标调整至需要生成目录的地方
02. 按下[Ctrl+Shift+P]快捷键,输入[Markdown All in One: Create Table of Contents],然后回车执行即可
2024-07-15 11:16:14 +08:00
dd9dc480fa 添加目录 2024-07-15 11:06:30 +08:00
2b6ad265a6 格式修订 2024-07-15 11:03:31 +08:00
57b98b7f2d 修订格式及部分内容 2024-07-15 11:01:41 +08:00
fe3be0a3a0 修复部分格式错误 2024-07-14 17:09:55 +08:00
a8b48821f9 新增VCPKG编译错误及其处理方法 2024-07-14 17:06:27 +08:00
841f5ac800 修复附件链接 2024-05-31 16:56:41 +08:00
ab85d05e51 修复附件链接 2024-05-31 16:53:01 +08:00
193f52f86d 添加osgEarth创建六边形网格文章 2024-05-31 16:50:44 +08:00
5706f8c05a 修正目录错误 2024-05-13 15:29:33 +08:00
10 changed files with 420 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vscode/settings.json

View File

@ -0,0 +1,61 @@
# RK3588实机编译Qt5.15.13
## 目录
- [RK3588实机编译Qt5.15.13](#rk3588实机编译qt51513)
- [目录](#目录)
- [一、准备工作](#一准备工作)
- [二、编译安装](#二编译安装)
- [2.1 配置Qt(configure)](#21-配置qtconfigure)
- [2.2 编译](#22-编译)
- [2.3 安装](#23-安装)
- [附录A常见编译错误](#附录a常见编译错误)
- [1. QBasicMutex::lockInternal(int)重定义](#1-qbasicmutexlockinternalint重定义)
## 一、准备工作
- 下载Qt源码包本文以5.15.13为例如需编译其它版本下载对应版本的源代码即可注意版本不同时命令中的版本号与实际版本同步下载Qt源码包[Qt5.15.13源码链接](https://download.qt.io/archive/qt/5.15/5.15.13/single/)
- 通过以下命令行解压源代码至编译目录(需足够的磁盘空间,一般在用户目录新建)
> sudo xz -d qt-everywhere-src-5.15.13.tar.xz
> sudo tar -xvf qt-everywhere-src-5.15.13.tar
- 安装编译环境
> sudo apt-get install build-essential perl python git
- 安装依赖库
> sudo apt-get install libx11-*
> sudo apt-get install libx11*
>
> sudo apt-get install libxcb-*
> sudo apt-get install libxcb*
>
> sudo apt-get install libxkbcommon-dev
> sudo apt-get install libxkbcommon-x11-dev
> sudo apt-get install libxcb-xinerama0
> sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
## 二、编译安装
### 2.1 配置Qt(configure)
切换至解压出来的Qt目录中运行以下命令如果权限不足使用sudo执行注意其中的-prefix参数为最终Qt库的安装目录/home/firefly/Qt5.15.13),应根据实际环境进行修改,在命令行中执行修改后的命令:
> ./configure -prefix /home/firefly/Qt5.15.13 -confirm-license -opensource -release -make libs -xplatform linux-aarch64-gnu-g++ -pch -qt-libjpeg -qt-libpng -qt-zlib -no-sse2 -no-openssl -no-cups -no-glib -no-dbus -xcb -no-separate-debug-info -opengl es2 -egl -eglfs -qpa xcb -linuxfb -recheck-all -skip webengine -nomake examples -nomake tests -shared -skip purchasing -skip quick3d -skip sensors -skip speech -skip datavis3d -skip andriodextras -skip gamepad
### 2.2 编译
配置成功后,运行以下命令编译代码(-j8表示使用8线程并行编译可根据需要或实际情况修改该数值
> sudo make -j8
### 2.3 安装
编译成功后运行以下命令打包安装Qt库打包安装后的库可直接压缩后在其它同样或类似环境中解压使用
> sudo make install
## 附录A常见编译错误
### 1. QBasicMutex::lockInternal(int)重定义
- 错误描述:
> qmutex_linux.cpp:multiple definition of 'QBasicMutex::lockInternal(int)',
- 解决问题:
> As in qmutex.cpp it directly" #include qmutex_linux.cpp", as a result the content of qmutex_linux.cpp will be part of qmutex.cpp.And in the thread.pro, the SOURCES +=qmutex.cpp qmutex_linux.cpp, then during link, the two file have same symbols will be detected.When I delete qmutex_linux.cpp from SOURCES, there is no problem any more.
[参考文章](https://blog.csdn.net/qq_43417144/article/details/130680388)

View File

@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<map name = "ddmap" type="projected" version="2">
<options>
<terrain driver = "rex" lighting = "true" skirt_ratio="0.05" min_tile_range_factor = "6" first_lod = "0" blending = "false" color = "#ffffffff" tile_size = "17" normalize_edges = "true" compress_normal_maps = "false" normal_maps = "true" min_expiry_frames = "0" min_expiry_time = "0"/>
<!-- <profile>plate-carre</profile> -->
<profile>spherical-mercator</profile>
</options>
<image name="world" driver="tms" opacity = "1.0" format="png">
<url>E:/GISData/Imagery/tms.xml</url>
</image>
</map>

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 KiB

View File

@ -0,0 +1,174 @@
# osgEarth构建六边形网格兵棋地图示例
  在osgEarth中添加了osg::Geode绘制蜂窝状六边形网格效果包括墨卡托平面地图地理坐标平面地图三维地球等多种模式
![alt text](assets/osgEarth六边形网格/image.png)
```c++
// 函数:创建六边形蜂窝网格线,三维地球
osg::ref_ptr<osg::Geometry> createHexagonWireframe(const osgEarth::GeoExtent& extent, float radius, int rows, int cols) {
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
auto fromSRS = osgEarth::SpatialReference::get("wgs84");
auto srs = extent.getSRS();
// 计算每个六边形中心点的地理坐标
float height = std::sqrt(3.0f) * radius;
float lonDelta = radius;// extent.width() / cols;
float latDelta = radius;// extent.height() / rows;
for (int row = 0; row < rows; ++row) {
for (int col = 0; col < cols; ++col) {
float lonDelta = col * 1.5f * radius;
float latDelta = row * height;
if (col % 2 == 1)
latDelta += height / 2.0f;
float lon = 108.0 + lonDelta;
float lat = 35.0 + latDelta;
osg::Vec3d centerGeo(lon, lat, 3000.0);
// 计算六边形的顶点
for (int i = 0; i < 6; ++i)
{
float angle = osg::PI * 2.0f * float(i) / 6.0f;
float x = radius * std::cos(angle);
float y = radius * std::sin(angle);
osg::Vec3d vertexXYZ;
osgEarth::GeoPoint pppp(fromSRS, osg::Vec3d(lon + x, lat + y, 1.0));
pppp.transformInPlace(srs);
pppp.toWorld(vertexXYZ);
//vertices->push_back(centerXYZ + vertexXYZ - centerGeo);
vertices->push_back(vertexXYZ);
}
}
}
geometry->setVertexArray(vertices);
osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt(GL_LINES);
int numHexagons = rows * cols;
for (int i = 0; i < numHexagons; ++i) {
int offset = i * 6;
for (int j = 0; j < 6; ++j) {
indices->push_back(offset + j);
indices->push_back(offset + (j + 1) % 6);
}
}
geometry->addPrimitiveSet(indices);
// 启用 VBO
geometry->setUseVertexBufferObjects(true);
// 设置线宽
osg::ref_ptr<osg::StateSet> stateSet = geometry->getOrCreateStateSet();
osg::ref_ptr<osg::LineWidth> lineWidth = new osg::LineWidth(1.0f); // 设置线宽为 1.0
stateSet->setAttributeAndModes(lineWidth, osg::StateAttribute::ON);
return geometry;
}
// 函数:创建六边形蜂窝网格线,平面地图
osg::ref_ptr<osg::Geometry> createHexagonWireframe(double startX,double startY, float radius, int rows, int cols) {
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
// 计算每个六边形中心点的地理坐标
float height = std::sqrt(3.0f) * radius;
for (int row = 0; row < rows; ++row)
{
for (int col = 0; col < cols; ++col)
{
float xDelta = col * 1.5f * radius;
float yDelta = row * height;
if (col % 2 == 1)
yDelta += height / 2.0f;
float lon = startX + xDelta;
float lat = startY + yDelta;
// 计算六边形的顶点
for (int i = 0; i < 6; ++i)
{
float angle = osg::PI * 2.0f * float(i) / 6.0f;
float x = radius * std::cos(angle);
float y = radius * std::sin(angle);
//vertices->push_back(centerXYZ + vertexXYZ - centerGeo);
vertices->push_back(osg::Vec3d(lon + x, lat + y, 1.0));
}
}
}
geometry->setVertexArray(vertices);
osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt(GL_LINES);
int numHexagons = rows * cols;
for (int i = 0; i < numHexagons; ++i) {
int offset = i * 6;
for (int j = 0; j < 6; ++j) {
indices->push_back(offset + j);
indices->push_back(offset + (j + 1) % 6);
}
}
geometry->addPrimitiveSet(indices);
// 启用 VBO
geometry->setUseVertexBufferObjects(true);
// 设置线宽
osg::ref_ptr<osg::StateSet> stateSet = geometry->getOrCreateStateSet();
osg::ref_ptr<osg::LineWidth> lineWidth = new osg::LineWidth(1.0f); // 设置线宽为 1.0
stateSet->setAttributeAndModes(lineWidth, osg::StateAttribute::ON);
return geometry;
}
int main(int argc, char* argv[])
{
auto ddMap = osgDB::readNodeFile("E:/GISData/Imagery/2dmap.earth");
auto mapNode = osgEarth::MapNode::findMapNode(ddMap);
osgEarth::GeoPoint start(osgEarth::SpatialReference::get("wgs84"), 108.0, 35.0);
start.transformInPlace(mapNode->getMapSRS());
auto hexagon222 = createHexagonWireframe(start.x(), start.y()
, 500, 100, 100);
hexagon222->getOrCreateStateSet()->setAttribute(new osg::Depth(osg::Depth::ALWAYS, 0.0, 1.0, false), osg::StateAttribute::ON);
osgEarth::GLUtils::setLighting(hexagon222->getOrCreateStateSet(), osg::StateAttribute::OFF);
mapNode->addChild(hexagon222);
auto m = new osgEarth::EarthManipulator;
osgViewer::Viewer viewer;
viewer.setSceneData(ddMap);
viewer.setCameraManipulator(m);
viewer.getCamera()->addCullCallback(new osgEarth::AutoClipPlaneCullCallback(mapNode));
viewer.realize();
m->setViewpoint(osgEarth::Viewpoint("", 108, 35, 0.0, 0.0, -89.9, 100000));
return viewer.run();
}
```
## 附件
![2dmap.earth](assets/osgEarth六边形网格/2dmap.earth)
## 性能问题
* 考虑使用instanced drawing
* 使用kd-tree
* ...

View File

@ -0,0 +1,84 @@
# vcpkg安装库失败常见错误及其解决方法
## 目录
- [vcpkg安装库失败常见错误及其解决方法](#vcpkg安装库失败常见错误及其解决方法)
- [目录](#目录)
- [1. 科学上网](#1-科学上网)
- [1.1 控制台设置代理](#11-控制台设置代理)
- [1.2 vcpkg包下载失败](#12-vcpkg包下载失败)
- [1.3 osg/osgEarth网络代理环境变量](#13-osgosgearth网络代理环境变量)
- [2. 遇到某些库编译错误时,在本地修改代码并使用修改后的代码编译](#2-遇到某些库编译错误时在本地修改代码并使用修改后的代码编译)
- [3. vcpkg ports内可以修改库的配置如工程目录windows SDK版本以及部分错](#3-vcpkg-ports内可以修改库的配置如工程目录windows-sdk版本以及部分错)
- [4. 找不到Windows SDK库的错误修改https://github.com/microsoft/vcpkg/issues/8288](#4-找不到windows-sdk库的错误修改httpsgithubcommicrosoftvcpkgissues8288)
- [5. vc错误: `error MSB4115: 函数“exists”只接受标量值但其参数“$(ForceImportBeforeCppTargets)”的计算结果为`](#5-vc错误-error-msb4115-函数exists只接受标量值但其参数forceimportbeforecpptargets的计算结果为)
- [5. 编译GDAL 出现 +{}; 加号不明确](#5-编译gdal-出现--加号不明确)
- [6. Windows 7 Python 3.8](#6-windows-7-python-38)
## 1. 科学上网
vcpkg中大部份依赖均托管在github仓库中由于国内特殊的网络环境导致github大部分时间无法正常访问尤其是下载较大源码包或文件时会出现网络错误此时需要通过科学上网措施目前统一使用Mielink建立代理上网建立代理后一般会有一个本地代理端口如果配置的不是全局代理那么有时需要在控制台设定上网代理下面介绍代理配置方法及一些网络相关的其它错误...
### 1.1 控制台设置代理
控制台设置网络代理需要将2801修改成本机的科学上网代理端口
* set HTTP_PROXY=http://127.0.0.1:2801
* set HTTPS_PROXY=http://127.0.0.1:2801
### 1.2 vcpkg包下载失败
* 有时使用vcpkg安装指定库时由于网络抽风有时会出现无法成功下载某些源码包的情况此时可先使用vcpkg安装一次确认源码包的下载目录及保存的文件名此二者有时不一致然后使用以下方法下载压缩包重命名后放在vcpkg的download目录中即可
* 关于库下载错误可以通过迅雷或其它工具下载然后添加到download目录注意从命令行确认保存的文件名
### 1.3 osg/osgEarth网络代理环境变量
* set OSGEARTH_HTTP_DEBUG=1
* set OSG_CURL_PROXY="127.0.0.1"
* set OSG_CURL_PROXYPORT=2801
## 2. 遇到某些库编译错误时,在本地修改代码并使用修改后的代码编译
正常使用vcpkg install xxxx安装库时出现编译错误通过编译日志可以定位到具体的编译错误但是默认情况下每次install时都会从压缩包中重新解压一份新的代码到本地临时目录因此无法对源代码进行修改并使用修复后的代码进行编译安装此时只需要在install时额外指定--editable选项即可使本次编译不生成临时源码目录在一个固定的源码目录中然后可手工编辑修改此目录中源代码然后再使用install此时仍需指定--editable选项安装这时就会使用修改后的代码进行编译了...
通过prompt启动然后进入vcpkg目录
VCPKG install 库名 --editable可以在编译前修改库源码
## 3. vcpkg ports内可以修改库的配置如工程目录windows SDK版本以及部分错
## 4. 找不到Windows SDK库的错误修改https://github.com/microsoft/vcpkg/issues/8288
## 5. vc错误: `error MSB4115: 函数“exists”只接受标量值但其参数“$(ForceImportBeforeCppTargets)”的计算结果为`
* 报错信息:
> 1>节点 1 上的项目“xxxxxx\buildtrees\libpq\x64-windows-dbg\libpq.vcxproj”(默认目标)。
> 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Current.targets(14,11): error MSB4115: 函数“exists”只接受标量值但其参数“$(ForceImportBeforeCppTargets)”的计算结果为“C:/Users/gz/Desktop/vcpkg-2023.08.09/scripts/buildsystems/msbuild/vcpkg.targets;C:/Users/gz/Desktop/vcpkg-2023.08.09/buildtrees/libpq/x64-windows-dbg/vcpkg-libs.props”不是标量值。 [xxxxxx\buildtrees\libpq\x64-windows-dbg\libpq.vcxproj]
> 1>已完成生成项目“xxxxxx\buildtrees\libpq\x64-windows-dbg\libpq.vcxproj”(默认目标)的操作 - 失败。
* 参考链接https://github.com/conan-io/conan/issues/7806
* 解决方案:
> 修改对应库ports目录内的msvc.cmake文件
> /p:ForceImportBeforeCppTargets=\"${SCRIPTS}/buildsystems/msbuild/vcpkg.targets\"
>
> /p:ForceImportBeforeCppTargets=\"${build_path}/vcpkg-libs.props\"
## 5. 编译GDAL 出现 +[](){}; 加号不明确
* 错误信息:
> xxxxxx\buildtrees\gdal\src\v3.7.1-30395dad39\ogr\ogrsf_frmts\openfilegdb\filegdbindex_write.cpp(1298): error C2593: “operator +”不明确
> xxxxxx\buildtrees\gdal\src\v3.7.1-30395dad39\ogr\ogrsf_frmts\openfilegdb\filegdbindex_write.cpp(1298): note: 可能是“内置 C++ operator+(void (__cdecl *)(std::vector<GByte,std::allocator<_Ty>> &,const __int64 &,int))”
> with
> [
> _Ty=GByte
> ]
> xxxxxx\buildtrees\gdal\src\v3.7.1-30395dad39\ogr\ogrsf_frmts\openfilegdb\filegdbindex_write.cpp(1298): note: 或 “内置 C++ operator+(void (__vectorcall *)(std::vector<GByte,std::allocator<_Ty>> &,const __int64 &,int))”
> with
> [
> _Ty=GByte
> ]
> xxxxxx\buildtrees\gdal\src\v3.7.1-30395dad39\ogr\ogrsf_frmts\openfilegdb\filegdbindex_write.cpp(1298): note: 尝试匹配参数列表“(OpenFileGDB::FileGDBTable::CreateSpatialIndex::<lambda_0019e43095a67889bd1988df31ec838d>)”时
* 原因分析由于C++版本原因,低版本并不支持该转换,因此直接去掉转换即可
* 解决方法尝试去掉lambda前面的加号(该加号用于将lambda表达式转为传统函数指针兼容老代码
## 6. Windows 7 Python 3.8
如果用到的库依赖了Python3.8以上的版本是无法在windows7正常运行的解决办法是用3.8狸猫换太子无痛替换掉vcpkg自动下载的python
貌似打补丁也可以实现让windows7支持3.9.2运行

23
代码规范/README.md Normal file
View File

@ -0,0 +1,23 @@
# [代码规范](./cppStyleGuide/StyleGuide.md)
引用模板
* [google cpp guide](https://google.github.io/styleguide/cppguide.html)
* [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines)
* Qt
* osg
* 源码文件编码utf-8
# [git仓库管理](./gitStore/git.md)
* 仓库创建流程
* git钩子
# 代码审查
* 代码规范检查
* C/C++ 静态代码检查工具cppCheck
# CMake
* 快速搭建基础项目(持续更新)
* 编译器配置(持续更新)

View File

@ -0,0 +1,61 @@
# c++ 代码风格规范
## 源代码文件命名
##### 1. 前要
**通常情况下每个.cpp文件应该有一个配套的.h文件。当然也有例外的情况例如c++模板类的实现)。正确使用头文件会大大改善代码的可读性和执行文件的大小和性能.**
> 头文件应能独立编译,就是头文件的使用者和构建工具在导入文件时无需任何特殊的前提条件就能完成代码编译。具体来说,头文件要有头文件防护符,并导入它所需的所有其它头文件。
> 当编写c++模板时应保证模板的实现声明和实现都在同一个文件里。一般,写模板时源码文件以.hpp命名。
> 避免编写依赖某个构建工具的代码。例如项目的构建依赖于VSCode的一个插件使用其他的构建工具项目无法构建且生成
> 避免前向声明
##### 2. 文件命名
* **新建c++类[.h 或 .hpp]**
> 新建类文件时,尽量保证文件名与导出(外部调用)的类名保持一致(一个头文件中可能包含好几个类)。
> Help.h
```cpp
class Help{}
```
Help.hpp
```cpp
template<typename T>
class Help{}
```
##### 3. 防护符
* **要保证头文件带有防护重复引用预处理头**
```cpp
#pragma once
```
```cpp
#ifndef HELP_H
#define HELP_H
#endif
```
## 命名规范
##### 1. 命名空间[namespace]
##### 2. 类[class]
##### 3. 结构体[struct]
##### 4. 模板[template]
##### 5. 私有函数或变量[private]
##### 6. 共有函数或变量[public]
##### 7. 受保护函数或变量[protected]
##### 8. 预处理[#define]
##### 9. 内联函数[inline]
##### 10. 常量[const]
##### 11. 静态变量或函数[static]

View File

@ -0,0 +1 @@


View File

@ -22,7 +22,7 @@
1. 打开计算机文件管理器 1. 打开计算机文件管理器
2. 在【此电脑】右键 2. 在【此电脑】右键
3. 在弹出的菜单中,点击【映射网络驱动器】 3. 在弹出的菜单中,点击【映射网络驱动器】
4. 在弹出的界面中,【文件夹】输入框输入 **\\192.168.1.11\Shared** 4. 在弹出的界面中,【文件夹】输入框输入 **\\\\192.168.1.11\\Shared**
5. 勾选输入框下面的【登陆时重新连接】和【使用其他凭据连接】 5. 勾选输入框下面的【登陆时重新连接】和【使用其他凭据连接】
6. 点击【完成】按钮 6. 点击【完成】按钮
7. 在弹出的界面中输入用户名和密码,并勾选【记住我的凭据】 7. 在弹出的界面中输入用户名和密码,并勾选【记住我的凭据】