Skip to main content

· 1分钟阅读
xkyii

购买

99一年, 2C2G+40G, 算便宜的.

基本信息

  • 2024.11.27购买, 一年期
  • 公网IP: 47.115.206.198
  • root密码: Aly

基本配置

ssh

需要在安全组里允许22端口,才能远程使用ssh登录

账号

新建账号


## 新建账号
```shell
# 添加用户
useradd -r -m -s /bin/bash xkyii

# 查看用户
id xkyii

# 修改密码(指定用户)
passwd xkyii
# 修改密码(当前用户)
passwd

# 查看密码文件
cat /etc/passwd

# 加入root组
usermod -g root xkyii
# 查看
id xkyii

免密

· 1分钟阅读
xkyii

环境

  • Windows 10
  • 9.0.100-preview.7.24407.12
  • Microsoft Visual Studio Community 2022 (64 位) - Current 版本 17.11.2

工程

  • 新建项目

  • 修改项目配置WinFormAot.csproj:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<!-- 禁止裁剪和AOT冲突的报错 -->
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>

<!-- 支持winxp可以试试加上
<WindowsSupportedOSPlatformVersion>5.1</WindowsSupportedOSPlatformVersion>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetPlatformMinVersion>5.1</TargetPlatformMinVersion>
-->
</PropertyGroup>
</Project>
  • 发布配置参考:

  • 发布

· 2分钟阅读
xkyii

环境

  • Clion 2024.2
  • Windows 10
  • WSL 2.0.9
❯ wsl -v
WSL 版本: 2.0.9.0
内核版本: 5.15.133.1-1
WSLg 版本: 1.0.59
MSRDC 版本: 1.2.4677
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows 版本: 10.0.19045.2965

准备

调试

编译完成之后,需要选定可执行文件

问题

fatal error: release.h: No such file or directory

确实没有这个文件,因为这个文件是src/mkreleasehdr.sh生成的,但是编译的最前面就已经报错:

sh: 1: ./mkreleasehdr.sh: not found

检查了一下, 文件确实存在,并且权限也是够的,尝试运行一下:

./mkreleasehdr.sh

可能是换行符的问题,修改为LR

重新编译即可

连接IP不对

使用localhost和本机IP可能都会连不上,进到WSL命令行,看下当前IP,应该可以

取消保护模式

修改redis.conf:(改这个文件好像没用)

protected-mode no

启动的时候加个参数:

--protected-mode no

· 3分钟阅读
xkyii

资料

重复类型

最简单明了的是完全一样的代码片段。此外,还有如下类型的重复代码:

  1. 类型 Ⅰ,代码片段中除了空格、注释以及换行以外的内容完全一致
  2. 类型 Ⅱ,代码片段中除了空格、注释、换行以及变量名以外的内容完全一致
  3. 类型 Ⅲ,代码片段中除了空格、注释、换行以及变量名以外的语句可能有增删改,功能不变
  4. 类型 Ⅳ,两个或更多个代码段执行相同的运算,但通过不同的语法和变量来实现。

检测工具

不同的重复代码检测工具,由于在实现算法上有所不同,其所能检测的重复代码类型也不尽相同,如下表所示。

名称SimianPMD-CPDCloneDRCCCDCCFinderBauhausCodePro
检测类型Ⅰ,ⅡⅠ,ⅡⅠ,ⅡⅠ,Ⅱ,ⅢⅠ,Ⅱ,Ⅲ
支持语言C/C++,JavaC/C++,JavaC/C++,JavaC,JavaC/C++,JavaC/C++,JavaJava
授权类型商用,可免费开源商用,可免费开源开源商用,可免费开源
推荐星级**************

试试

准备

把两个目录映射出来

cmd
mklink /J mlcache-anno D:\Code\thzt\mlcache\mlcache-anno
mklink /J jetcache-anno D:\Code\xkrof\jetcache-2.7.5\jetcache-anno

automoss

jplag

# jdk依赖
scoop install openjdk21

pmd

  • Releases · pmd/pmd (github.com)下载版本
  • 解压,进入bin目录
  • 启动GUI pmd cpdgui
  • 选择目录,GO
  • 可以比较出文件及行数,暂时没有找到百分比之类的统计数据

· 2分钟阅读
xkyii

环境

❯ wsl -v
WSL 版本: 2.0.9.0
内核版本: 5.15.133.1-1
WSLg 版本: 1.0.59
MSRDC 版本: 1.2.4677
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows 版本: 10.0.19045.2965

配置

sudo apt update
sudo apt upgrade

安装C++相关

sudo apt-get update
sudo apt-get install cmake gcc clang gdb build-essential

wsl 代理

# WSL通过Win访问网络,所以WSL的网关指向的是Windows,DNS服务器指向的也是Windows,设置WSL的proxy为win的代理ip+端口即可
# WSL中的DNS server在/etc/resolv.conf中查看,该文件是由/etc/wsl.conf自动生成的。
# 如果关闭了wsl.conf中自动生成resolve.conf并自行修改了resolve.conf,DNS nameserver并不是本机win ip
# 需要开启wsl.conf的自动生成,再运行以下命令
# https://zhuanlan.zhihu.com/p/153124468

# 添加到环境变量设置中,例如~/.zshrc
export HOST_IP=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
export HTTPS_PROXY="http://${HOST_IP}:7890"
export HTTP_PROXY="http://${HOST_IP}:7890"
# export ALL_PROXY="http://$host_ip:7890"

vcpkg

sudo apt-get update
sudo apt-get install build-essential tar curl zip unzip pkg-config
git clone https://github.com/microsoft/vcpkg
./vcpkg/bootstrap-vcpkg.sh

clion

  • 配置Toolchains

  • 配置CMake -> CMake Options: -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake

  • Reload项目:

参考

· 5分钟阅读
xkyii

报错

在客户端连接时,出现:

Client On Error: Error: write ECONNABORTED Config right?

docker

docker compose

  redis:
image: redis:6.2.7
restart: always
hostname: redis
container_name: mlcache-redis
privileged: true
ports:
- "6399:6379"
environment:
- TZ=Asia/Shanghai
volumes:
- ./data/redis/data:/data
- ./data/redis/logs:/logs
# - ./data/redis/redis.conf:/etc/redis/redis.conf
- ../redis/redis.conf:/etc/redis/redis.conf
command: ["redis-server","/etc/redis/redis.conf"]
# command: ["redis-server"]

redis.conf

默认配置, 去redis/redis根目录下找redis.conf,最好是找对应版本的tag

尝试

尝试一

不使用配置启动,连接正常,即:

  redis:
image: redis:6.2.7
restart: always
hostname: redis
container_name: mlcache-redis
privileged: true
ports:
- "6399:6379"
environment:
- TZ=Asia/Shanghai
volumes:
- ./data/redis/data:/data
- ./data/redis/logs:/logs
# - ./data/redis/redis.conf:/etc/redis/redis.conf
# - ../redis/redis.conf:/etc/redis/redis.conf
# command: ["redis-server","/etc/redis/redis.conf"]
command: ["redis-server"]

所以大致认为配置有问题

尝试二

重新启用配置

  redis:
image: redis:6.2.7
restart: always
hostname: redis
container_name: mlcache-redis
privileged: true
ports:
- "6399:6379"
environment:
- TZ=Asia/Shanghai
volumes:
- ./data/redis/data:/data
- ./data/redis/logs:/logs
- ../redis/redis.conf:/etc/redis/redis.conf
command: ["redis-server","/etc/redis/redis.conf"]

看下日志: (docker logs $container_id)

2024-04-10 16:57:55 1:C 10 Apr 2024 16:57:55.529 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2024-04-10 16:57:55 1:C 10 Apr 2024 16:57:55.529 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started
2024-04-10 16:57:55 1:C 10 Apr 2024 16:57:55.529 # Configuration loaded
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 * monotonic clock: POSIX clock_gettime
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # Warning: Could not create server TCP listening socket ::1:6379: bind: Cannot assign requested address
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 * Running mode=standalone, port=6379.
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # Server initialized
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 * Loading RDB produced by version 6.2.7
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 * RDB age 35 seconds
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 * RDB memory usage when created 0.87 Mb
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 # Done loading RDB, keys loaded: 0, keys expired: 0.
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.534 * DB loaded from disk: 0.003 seconds
2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.534 * Ready to accept connections

其中有个警告: Warning: Could not create server TCP listening socket ::1:6379: bind: Cannot assign requested address, 绑定端口失败

redis.conf中,找到bind相关的一段:

# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
# will only be able to accept client connections from the same host that it is
# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 -::1

bind这行注释掉

尝试三

重新启动容器,看日志:

2024-04-10 17:02:40 1:C 10 Apr 2024 17:02:40.645 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2024-04-10 17:02:40 1:C 10 Apr 2024 17:02:40.645 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started
2024-04-10 17:02:40 1:C 10 Apr 2024 17:02:40.645 # Configuration loaded
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.645 * monotonic clock: POSIX clock_gettime
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.645 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.645 * Running mode=standalone, port=6379.
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.646 # Server initialized
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.646 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * Loading RDB produced by version 6.2.7
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * RDB age 89 seconds
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * RDB memory usage when created 0.77 Mb
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 # Done loading RDB, keys loaded: 0, keys expired: 0.
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * DB loaded from disk: 0.001 seconds
2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * Ready to accept connections

有个警告: overcommit_memory is set to 0!

尝试二中的bind部分修改为

bind 0.0.0.0

overcommit_memory is set to 0!这个问题就没有了

· 2分钟阅读
xkyii

资料

环境

  • Windows 10
❯ zig version
0.11.0

使用

新建项目

mkdir webuix
cd webuix
zig init-exe

引入webui

  • 修改build.zig文件,加入:
    const zig_webui = b.dependency("zig-webui", .{
.target = target,
.optimize = optimize,
.enable_tls = false,
.is_static = true,
});

// add module
exe.addModule("webui", zig_webui.module("webui"));

// link library
exe.linkLibrary(zig_webui.artifact("webui"));
  • 添加或修改build.zig.zon, (在dependencies中增加zigwebui):
.{
.name = "webuix",
.version = "0.0.1",
.minimum_zig_version = "0.11.0",
.dependencies = .{
.@"zig-webui" = .{
// It is recommended to replace the following branch with commit id
.url = "https://github.com/webui-dev/zig-webui/archive/main.tar.gz",
.hash = "12201a01f9682c7b2caa3abe27e7aef824a3c421393b84e96aa2615e284bd87cd8bd",
},
},
.paths = .{
"",
},
}
const webui = @import("webui");

pub fn main() !void {
var nwin = webui.newWindow();
_ = nwin.show("<html><head><script src=\"webui.js\"></script></head> Hello World ! </html>");
webui.wait();
}

· 5分钟阅读
xkyii

entrypoint

默认是/opt/bitnami/scripts/etcd/entrypoint.sh,当第一cmd参数是/opt/bitnami/scripts/etcd/run.sh时,会启动setup流程

#!/bin/bash
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0

# shellcheck disable=SC1091

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes

# Load libraries
. /opt/bitnami/scripts/libbitnami.sh
. /opt/bitnami/scripts/liblog.sh

# Load etcd environment variables
. /opt/bitnami/scripts/etcd-env.sh

print_welcome_page

if [[ "$1" = "/opt/bitnami/scripts/etcd/run.sh" ]]; then
info "** Starting etcd setup **"
/opt/bitnami/scripts/etcd/setup.sh
info "** etcd setup finished! **"
fi

echo ""
exec "$@"

顺序是先setup.sh(如果指定了的话) ,后run.sh

setup

文件是/opt/bitnami/scripts/etcd/setup.sh

#!/bin/bash
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0

# shellcheck disable=SC1091

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes

# Load libraries
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/libetcd.sh

# Load etcd environment settings
. /opt/bitnami/scripts/etcd-env.sh

# Ensure etcd environment settings are valid
etcd_validate
# Ensure etcd is stopped when this script ends.
trap "etcd_stop" EXIT
# Ensure 'daemon' user exists when running as 'root'
am_i_root && ensure_user_exists "$ETCD_DAEMON_USER" --group "$ETCD_DAEMON_GROUP"
# Ensure etcd is initialized
etcd_initialize

这里最关键的地方是etcd_initialize函数,要确定etcd已经初始化,这个函数是在/opt/bitnami/scripts/libetcd.sh中定义的

run

文件是/opt/bitnami/scripts/etcd/run.sh,最后执行的是etcd命令(${cmd[@]})

#!/bin/bash
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0

# shellcheck disable=SC1090,SC1091

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes

# Load libraries
. /opt/bitnami/scripts/liblog.sh
. /opt/bitnami/scripts/libos.sh
. /opt/bitnami/scripts/libvalidations.sh
. /opt/bitnami/scripts/libetcd.sh

# Load etcd environment variables
. /opt/bitnami/scripts/etcd-env.sh

is_empty_value "$ETCD_ROOT_PASSWORD" && unset ETCD_ROOT_PASSWORD
if [[ -f "$ETCD_NEW_MEMBERS_ENV_FILE" ]]; then
debug "Loading env vars of existing cluster"
. "$ETCD_NEW_MEMBERS_ENV_FILE"
# We rely on the original value of ETCD_INITIAL_CLUSTER
# when bootstrapping a new cluster since
# we need all initial members to calcualte a same cluster_id
fi

declare -a cmd=("etcd")
# If provided, run using configuration file
# Using a configuration file will cause etcd to ignore other flags and environment variables
[[ -f "$ETCD_CONF_FILE" ]] && cmd+=("--config-file" "$ETCD_CONF_FILE")
cmd+=("$@")

info "** Starting etcd **"
if am_i_root; then
exec_as_user "$ETCD_DAEMON_USER" "${cmd[@]}"
else
exec "${cmd[@]}"
fi

自定义

如果启动过程中需要自定义一些内容,比如:

#!/bin/sh
./etcdctl user add root
./etcdctl --user=root --password="123456" user grant-role root root
./etcdctl --user=root --password="123456" auth enable
./etcdctl --user=root --password="123456" role add client
./etcdctl --user=root --password="123456" role add worker
./etcdctl --user=root --password="123456" user add worker
./etcdctl --user=root --password="123456" user grant-role worker worker
./etcdctl --user=root --password="123456" role grant-permission client read /hotcaffeine --prefix=true
./etcdctl --user=root --password="123456" role grant-permission worker readwrite /hotcaffeine --prefix=true

这些内容单独做个脚本放在entrypoint.sh的最后面执行是有点难度的,经常会出现:

{"level":"warn","ts":"2023-12-29T06:17:55.512582Z","logger":"etcd-client","caller":"v3@v3.5.11/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc0001508c0/127.0.0.1:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:2379: connect: connection refused\""}

因为初始化了之后会终止掉服务再重启。要么在初始化的时候自定义,要么再等服务完成重启完成

所以我目前的做法是直接把/opt/bitnami/scripts/libetcd.sh文件中的函数etcd_initialize改掉,然后映射覆盖掉。

覆盖etcd_initialize

/opt/bitnami/scripts/libetcd.sh复制出来,然后修改要自定义的地方,像这样:

etcd_configure_rbac() {

! is_etcd_running && etcd_start_bg
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"

is_boolean_yes "$ETCD_ON_K8S" && extra_flags+=("--endpoints=$(etcdctl_get_endpoints)")
if retry_while "etcdctl ${extra_flags[*]} member list" >/dev/null 2>&1; then
if retry_while "etcdctl ${extra_flags[*]} auth status" >/dev/null 2>&1; then
if etcdctl "${extra_flags[@]}" auth status | grep -q "Authentication Status: true"; then
info "Authentication already enabled"
else
info "Enabling etcd authentication"
is_boolean_yes "$ETCD_ON_K8S" && extra_flags=("--endpoints=$(etcdctl_get_endpoints)")
etcdctl "${extra_flags[@]}" user add root --interactive=false <<<"$ETCD_ROOT_PASSWORD"
etcdctl "${extra_flags[@]}" user grant-role root root
etcdctl "${extra_flags[@]}" auth enable
# 这里是自定义的内容
etcdctl "${extra_flags[@]}" role add client
etcdctl "${extra_flags[@]}" role add worker
etcdctl "${extra_flags[@]}" user add worker --interactive=false <<<"$ETCD_WORKER_PASSWORD"
etcdctl "${extra_flags[@]}" user grant-role worker worker
etcdctl "${extra_flags[@]}" role grant-permission client read /hotcaffeine --prefix=true
etcdctl "${extra_flags[@]}" role grant-permission worker readwrite /hotcaffeine --prefix=true
fi
fi
fi
etcd_stop
}

然后在volumes中将原来的文件覆盖掉

使用docker-compose

version: '3'

services:
etcd:
image: bitnami/etcd:latest
restart: always
container_name: etcd
ports:
- 2379:2379
- 2380:2380
volumes:
# 覆盖掉原始的文件
- ./libetcd.sh:/opt/bitnami/scripts/libetcd.sh
environment:
- ETCD_ROOT_PASSWORD=H&O%T=C9AFF]
- ETCD_WORKER_PASSWORD==+WK%&#*

· 3分钟阅读
xkyii

VsCode

安装

scoop install vscode

插件

WSL

wsl --version
WSL 版本: 2.0.9.0
内核版本: 5.15.133.1-1
WSLg 版本: 1.0.59
MSRDC 版本: 1.2.4677
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows 版本: 10.0.19045.3803
sudo apt-get install wget ca-certificates
sudo apt update
sudo apt-get install openssh-server g++ gdb make ninja-build rsync zip
sudo apt-get install cmake

C/C++

用VsCode连接到WSL,打开一个目录。

Ctrl+Shift+P -> CMake: Quick Start

选一套工具包

建一个项目, C++, Executable

直接开始调试

Zig

安装

中间可能会遇到snap无法安装软件的问题,是因为systemctlwsl中不支持,可以参考WSL 中的高级设置配置来启用。

我是跑了DamionGans/ubuntu-wsl2-systemd-script这个脚本 (虽说已经unsupported,但是目前对我还是有效的)

这里有讨论snapwsl中的问题 WSL2- Ubuntu 20.04 Snap store doesn't work due to systemd dependency · Issue #5126 · microsoft/WSL (github.com)

调试

  • 打开Wsl/Ubuntu终端
cd ~
mkdir zello
cd zello
zig init-exe
zig build
  • VsCode打开zello目录,创建文件.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Zig Launch (Ubuntu)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/zello",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": []
}
]
}
  • F5, 开始调试

缓存目录

默认情况下,zig build会生成两个目录:zig-outzig-cache,可以使用参数--prefix--cache-dir来指定:

zig build --prefix D:\Code\xkyss\xkyss.zpp\build\playz\v0.11\hello\zig-out --cache-dir D:\Code\xkyss\xkyss.zpp\build\playz\v0.11\hello\zig-cache

这里需要指定全目录,相对目录会报错:error: BadPathName

如果需要在VsCode调试调试,还需要修改一下.vscode/launch.json,(调整cwdprogram的目录):

{
"version": "0.2.0",
"configurations": [
{
"name": "Zig Launch (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/../../../build/playz/v0.11/hello/zig-out/bin/hello.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/../../../build/playz/v0.11/hello",
"environment": []
}
]
}

后记

其实不管是Windows、WSL、还是Remote Linux,只要安装了插件和工具链,都是可以开发且调试的

· 2分钟阅读
xkyii

资料

安装

官方文档里面说到是要去拉源码并编译:

git clone https://github.com/microsoft/vcpkg.git

但是我发现VS2022安装完C++的部分之后,自己就安装了vcpkg,并且在Developer Command Prompt for VS2022中自动配置环境变量,所以使用VS2022是自动支持的。

但是项目属性中如果需要有配置菜单,需要:

vcpkg integrate install

其他的按照官方文档来就可以了

清单方式

  • 进入工程目录
# 建立vcpkg配置
vcpkg new --application

# 添加依赖
vcpkg add port fmt
  • 修改安装目录

CMake + vcpkg

清单

执行vcpkg new --application之后就会生成清单文件vcpkg.json

编辑文件增加依赖, 例如:

{
"dependencies": [
{
"name": "nlohmann-json",
"version>=": "3.11.3"
}
]
}

安装

执行vcpkg install,会按照清单文件按照依赖,成功时会有类似以下提示:

The package nlohmann-json provides CMake targets:  

find_package(nlohmann_json CONFIG REQUIRED)
target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)

The package nlohmann-json can be configured to not provide implicit conversions via a custom triplet file:

set(nlohmann-json_IMPLICIT_CONVERSIONS OFF)

For more information, see the docs here:

https://json.nlohmann.me/api/macros/json_use_implicit_conversions/

速度把其中CMake相关的内容添加到CMakeLists.txt文件里面, 如:


# 将源代码添加到此项目的可执行文件。
add_executable (mlcache "mlcache.cpp" "mlcache.h" "Cache.cpp" "Cache.h" "demo/User.h" "demo/Config.h")

# 增加的这一段
find_package(nlohmann_json CONFIG REQUIRED)
target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)

if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET mlcache PROPERTY CXX_STANDARD 11)
endif()

这样头文件也能正确找到了

离线安装

%% 2024.08.21 %%