保持 cpu 唤醒

表现为操作卡顿、联网卡顿,
使用 wakelock 锁,shell 中输入:

1
2
3
4
5
6
7
8
9
10
11
# 获取 su 权限
su

# 保持 cpu 唤醒:
echo lock_me > /sys/power/wake_lock

# 解除 wakelock 锁:
echo lock_me > /sys/power/wake_unlock

# 注:容器内使用时命令前面加 unchroot,
# 对 /sys 分区操作时不需要(容器挂载了 /sys 分区)。

wifi关闭节能模式

Wi-Fi 进入节能模式
表现为不能全速传输,延时高。

1
2
3
4
# 查询节能状态
unchroot iw dev wlan0 get power_save
# 关闭节能模式
unchroot iw wlan0 set power_save off

找不到库Boost

1
2
3
4
5
6
set(Boost_DEBUG 1)
set(BOOST_ROOT "C:/Program Files/boostqww")


# SET (Boost_USE_STATIC_LIBS ON)
# SET (Boost_USE_STATIC_RUNTIME ON)

错误

1
Could NOT find Boost (missing: program_options system) (found suitable version "1.70.0", minimum required is "1.65.0")

Installing boost on Windows using MinGW-w64 (gcc 64-bit)
在CMakeLists.txt中set(Boost_DEBUG 1)
打印信息

1
2
Searching for SYSTEM_LIBRARY_RELEASE: boost_system-mgw13-mt-1_83;boost_system-mgw13-mt;boost_system-mgw13-mt;boost_system-mt-1_83;boost_system-mt;boost_system-mt;boost_system-mt;boost_system
Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: boost_program_options-mgw13-mt-1_83;boost_program_options-mgw13-mt;boost_program_options-mgw13-mt;boost_program_options-mt-1_83;boost_program_options-mt;boost_program_options-mt;boost_program_options-mt;boost_program_options

找不到文件名,所以修改C:\boost\lib中的文件名称libboost_system-mgw13-mt-d-x64-1_83.dll.a更改为libboost_system-mgw13-mt-1_83.dll.alibboost_program_options-mgw13-mt-d-x64-1_83.dll.a更改为libboost_program_options-mgw13-mt-1_83.dll.a
这里使用的是动态链接库

boost使用静态链接库(static libraries),报错需要libboost_program_options-mgw13-mt-1_83.dll.a

使用静态链接库:将libboost_program_options-mgw13-mt-sd-x64-1_83.a改名为libboost_program_options-mgw13-mt-1_83.a
可选的:在CMakeLists中set(Boost_USE_STATIC_LIBS ON)

找不到openssl

1
2
3
[cmake]   Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
[cmake] system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
[cmake] OPENSSL_INCLUDE_DIR) (Required is at least version "1.1.0")

在CMakeLists.txt中添加

1
set(OPENSSL_ROOT_DIR "C:/Program Files/OpenSSL-Win64")

missing: OPENSSL_CRYPTO_LIBRARY

1
2
3
4
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake] Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
[cmake] system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
[cmake] suitable version "3.2.0", minimum required is "1.1.0")

版本Win64OpenSSL-3_2_0缺少lib文件,安装Win64OpenSSL-3_1_4版本即可

1.安装mingw64并将其加入path环境变量
2.解压boost.7z到Program Files
3.cd "C:\Program Files\boost_1_83_0\tools\build"
4.构建b2:bootstrap.bat gcc
5.安装Boost.Build:b2 --prefix="C:\boost-build" install
6.构建需要的library,使用–with-library_name

1
.\tools\build\b2.exe  --build-dir="C:\Program Files\boost_1_83_0\build" --with-program_options toolset=gcc install

nohup <命令> &

nohup > 2>&1 &
后台运行,默认将输出信息放到文件nohup.out

ctrl+z

将正在运行的命令放入后台,并暂停程序。

jobs

查看后台进程

fg %

将后台程序放到前台运行

bg

将后台暂停运行的程序在后台继续运行

Ctrl+c

结束前台运行的程序

kill

结束程序
kill %
kill pid

ps显示进程树

ps -ef –forest
ps -afx

查看端口占用程序的pid

1
netstat -aon|findstr ":<port>"

查看对应pid的程序

1
tasklist|findstr "<pid>"

结束对应pid的进程

1
taskkill /T /F /PID <pid>

申请证书

先关闭服务器,防止端口占用,再运行下面的命令

1
certbot certonly --standalone

查看证书列表

1
certbot.exe  certificates

删除不需要的证书

1
certbot delete --cert-name <domain-name>

boost::program_options

1
2
3
4
5
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("compression,c", po::value<double>(), "set compression level")
;

help,h之间不能有空格,否则识别不出-h参数

g++使用include头文件目录时报错

1
2
3
$ g++.exe -I "C:\Program Files\boost\" hello.cpp  
g++.exe: fatal error: no input files
compilation terminated.

需要将\改为\\或者/

1
g++.exe -I "C:/Program Files/boost/" hello.cpp 

vscode中错误检查

Ctrl+Alt+p:选择c/c++编辑配置=>包含路径(includePath)=>换行添加,就可以运行intellisense进行语法检查了。
然后在.vscode/tasks.json中添加includePath,就能使用F5运行项目

1
2
3
4
5
6
7
8
9
10
{
"tasks": [
{
"args": [
"-I",
"<yourIncludePath>"
],
}
]
}

vscode的intellisense找不到头文件

删除文件夹下的.vscode后,将头文件目录放到includePath下面

常用命令

-j:多线程编译

1
2
3
4
5
6
7
8
9
10
11
12
cmake  -G "MinGW Makefiles" ..
mingw32-make.exe -j 12
或者
cmake --build .

cmake --install .
ctest.exe -VV
cpack -G ZIP

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..

宏定义可以在源文件中使用

target_compile_definitions

0%