跳转到内容

博客

VSCode C/CPP Environment

具体参考C++ 环境设置

在源代码文件夹下创建一个.vscode文件夹,里面包含c_cpp_properties.json,launch.json,tasks.json,各文件的具体含义可以参考VScode tasks.json和launch.json的设置,VSCode预定义变量

需要将MinGW路径更改为实际路径

{
"configurations": [
{
"name": "RHEL7.2->Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/scadacom/current/**"
],
"forcedInclude": [],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [ //Release
"-std=c++11",
"-w",
"-O2",
"-pipe",
"-m64",
"-D_REENTRANT",
"-DQT_SHARED",
"-DQT_NO_DEBUG_OUTPUT",
"-DQT_NO_DEBUG",
"-DQT_GUI_LIB",
"-DQT_NETWORK_LIB",
"-DQT_CORE_LIB",
"-DQT_SHARED"
]
},
{
"name": "RHEL7.2-WindowsLocal",
"includePath": [
"${workspaceFolder}/**",
"~/Documents/Codes/include/RHEL7.2S5.8.10/**",
"C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include"
],
"forcedInclude": [],
"defines": [],
"compilerPath": "C:/ProgramData/chocolatey/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [ //Release
"-std=c++11",
"-w",
"-O2",
"-pipe",
"-m64",
"-D_REENTRANT",
"-DQT_SHARED",
"-DQT_NO_DEBUG_OUTPUT",
"-DQT_NO_DEBUG",
"-DQT_GUI_LIB",
"-DQT_NETWORK_LIB",
"-DQT_CORE_LIB",
"-DQT_SHARED"
],
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**",
"~/Documents/Codes/include/RHEL7.2S5.8.10/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}

需要将MinGW路径更改为实际路径

{
"version": "0.2.0",
"configurations": [
{
"name": "QT-CPPGDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/wg_modbus_ats",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/debug/",
"environment": [],
//"symbolSearchPath": "C:\\Symbols",
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi",
"MIMode": "lldb"
},
// "logging": {
// "moduleLoad": false,
// "trace": true
// },
"visualizerFile": "my.natvis"
},
{
"name": "CMake-CPPGDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${workspaceFolderBasename}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
//"symbolSearchPath": "C:\\Symbols",
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi",
"MIMode": "lldb"
},
// "logging": {
// "moduleLoad": false,
// "trace": true
// },
"visualizerFile": "my.natvis"
}
]
}

该文件直接复制即可

{
"version": "2.0.0",
// "windows": {
// "options": {
// "shell": {
// "executable": "bash.exe",
// "args": ["-c"]
// }
// }
// },
"tasks": [
{
"label": "Qmake",
"type": "shell",
"command": "/usr/local/Trolltech/Qt-4.8.4/bin/qmake",
"args": [],
"group": "build",
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "Clean",
"type": "shell",
"command": "make",
"args": [
"clean"
],
"group": "build",
"presentation": {
"reveal": "silent",
"clear": true
}
},
{
"label": "MakeCompile",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"Clean",
"Qmake"
],
"command": "/usr/bin/make",
"args": [
],
"group": "build",
"presentation": {
// "reveal": "silent",
"clear": true
}
},
]
}

[1]. https://www.runoob.com/cplusplus/cpp-environment-setup.html

[2]. https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables

[3]. https://zhuanlan.zhihu.com/p/92175757

[4]. https://www.cnblogs.com/bpf-1024/p/11597000.html

[5]. https://zhuanlan.zhihu.com/p/87864677

Windows 10 同时使用WIFI和有线网卡

当有线网卡和无线网卡同时连接两个不同网络时,Windows默认将自动断开无线网络,使用有线网络连接

  • 什么是跃点数
  • 跃点数是为用于特殊网络接口的 IP 路由分配的值,用来标识与使用该路由有关的成本。 例如,可以根据链接速度、跃点计数或时间延迟来计算跃点数。 “自动跃点计数”是 Windows 中的一个新增功能,它可以自动为基于链接速度的本地路由配置跃点数。 默认情况下,将启用“自动跃点计数”功能,也可以进行手动配置,为其赋予一个具体的跃点数。
  • 当路由表中包含用于同一目的地的多个路由时,“自动跃点计数”功能便非常有用。 例如,如果您的计算机具有一个 10 兆位 (Mb) 的网络接口和一个 100 Mb 的网络接口,并且该计算机具有一个在两个网络接口上均已配置的默认网关,那么“自动跃点计数”功能就会为较慢的网络接口分配较高的跃点数。 该功能会强制流向 Internet 的所有流量,例如,使用可用的最快网络接口。

具体可以参考:有关IPv4路由中的“自动跃点计数”功能的说明

1. 根据上面的链接,选择合适的跃点数值:

Section titled “1. 根据上面的链接,选择合适的跃点数值:”

2. 打开 控制面板\网络和 Internet\网络连接,依次设置两个网络接口

Section titled “2. 打开 控制面板\网络和 Internet\网络连接,依次设置两个网络接口”

[1] https://blog.csdn.net/hehehe326/article/details/103547046

[2] https://support.microsoft.com/zh-cn/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes

从一个git仓库提交代码到另一个仓库

实际开发中,将repro_a仓库中的branch_a独立成为一个新的仓库repro_b。主要依靠git remote实现。

1. 把当前代码提交到另一个远程git仓库

Section titled “1. 把当前代码提交到另一个远程git仓库”

假如仓库repo_a当前位于branch_a,要求将branch_a的整个数据(包括提交历史)全部提取出来,并建立一个新的仓库repo_b。这里假设仓库repo_b已经被建立。 git remote add基本语法如下。name和url是必须的。

git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>

(1). 将仓库repo_b的URL添加到工作仓库的remote。

Section titled “(1). 将仓库repo_b的URL添加到工作仓库的remote。”
git remote add origin_repo_b git@server_ip:/path/repo_b.git

(origin_repo_b:自己起的名字,只要不与现有的remote名重复即可)

(git@server_ip:/path/repo_b.git:repo_b的远程路径)

git push origin_repo_b branch_a

(origin_repo_b:远程仓库repo_b的名字)

(branch_a:仓库repo_a的的branch_a分支)

(3). 克隆仓库repo_b,检查是否push成功。

Section titled “(3). 克隆仓库repo_b,检查是否push成功。”

2. 将一份相同的代码提交到多个不同的git托管服务器(多个git仓库)

Section titled “2. 将一份相同的代码提交到多个不同的git托管服务器(多个git仓库)”

方法非常相似,多使用到了命令git remote set-url --add [--push] <name> <newurl> 假设在远程的git服务器上又新增了一个仓库repo_c,现在要求repo_b、repo_c提交的代码必须一致。

(1). 将远程repo_c配置到当前的工作的本地git仓库中

Section titled “(1). 将远程repo_c配置到当前的工作的本地git仓库中”
git remote set-url --add origin_repo_b git@192.168.1.101:~/project/repo_c.git

这句话的意思是,将远程仓库git@192.168.1.101:~/project/repo_c.git也加入到origin_repo_b这个名字下面管理

(2). 将代码同时提交到远程仓库repo_b和远程仓库repo_c

Section titled “(2). 将代码同时提交到远程仓库repo_b和远程仓库repo_c”
git push origin_repo_b branch_a

(3). fatal: refusing to merge unrelated histories

Section titled “(3). fatal: refusing to merge unrelated histories”
git pull origin master --allow-unrelated-histories

[1]. Git-Configuration

带有 GitLab-Runner 的 GitLab CI-CD

在 GitLab CI/CD 的容器中运行 GitLab-Runner。

podman run –detach
–privileged
–name gitlab-runner
–network host
-v ${PWD}/config:/etc/gitlab-runner:z
docker.io/gitlab/gitlab-runner:latest

## 2.在容器中注册Runner```
podman exec -it gitlab-runner gitlab-runner register

按照说明配置跑步者。

[2]. https://zhuanlan.zhihu.com/p/385110311

[3]. Podman-Volume-和-SELinux [4]. 使用 Systemd 管理 Podman 容器

KVM PCI 直通## 1. 通过编辑 grub 配置文件启用 IOMMU。对于 Intel,引导计算机,并将`intel_iommu=on`附加到 grub 配置文件中`GRUB_CMDLINE_LINUX`行的末尾。```

vi /etc/default/grub … GRUB_CMDLINE_LINUX=“nofb splash=quiet console=tty0 … intel_iommu=on …

对于 AMD,引导计算机,并将`amd_iommu=on`附加到 grub 配置文件中`GRUB_CMDLINE_LINUX`行的末尾。```
vi /etc/default/grub
...
GRUB_CMDLINE_LINUX="nofb splash=quiet console=tty0 ... amd_iommu=on
...

2. 刷新 grub.cfg 文件并重新引导主机以使这些更改生效:```

Section titled “2. 刷新 grub.cfg 文件并重新引导主机以使这些更改生效:```”

grub2-mkconfig -o /boot/grub2/grub.cfg

reboot

## 3. 防止驱动程序与Device绑定。```
grubby --args="pci-stub.ids=10de:11fa" --update-kernel DEFAULT

10de:11fa:设备总线id,可以通过lspci -Dnn获取

4. 可选:函数透传如果某些 GPU 功能(例如音频)由于支持限制而无法传递到 VM,您可以修改 IOMMU 组内端点的驱动程序绑定,以仅传递必要的 GPU 功能。

Section titled “4. 可选:函数透传如果某些 GPU 功能(例如音频)由于支持限制而无法传递到 VM,您可以修改 IOMMU 组内端点的驱动程序绑定,以仅传递必要的 GPU 功能。”
  • 将 GPU 设置转换为 XML,并记下要阻止连接到主机驱动程序的端点的 PCI 地址。
  • 防止端点连接到主机驱动程序。- driverctl set-override 0000:02:00.1 vfio-pci

[2]. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/configuring_and_managing_virtualization/assembly_managing-gpu-devices-in-virtual-machines_configuring-and-managing-virtualization#proc_assigning-a-gpu-to-a-virtual-machine_assembly_managing-gpu-devices-in-virtual-machines

[3]. 命令行安装KVM虚拟化系统