岚天逸见

随笔分类 -  C/C++

1 2 3 4 5 ··· 12 下一页

✅ 如何安装 dlib 和 OpenCV(不带 Python 绑定)
摘要:dlib 是一个功能强大、跨平台的纯 C++ 库,专为机器学习和计算机视觉设计。它由 Davis King 开发并维护,以其简洁的 API、高性能和易用性而闻名。编译依赖 C++ 编译器和构建工具 CMake,C++ 编译器需要支持 C++14。OpenCV(全称:Open Source Compu 阅读全文

posted @ 2026-01-16 17:20 岚天逸见 阅读(7) 评论(0) 推荐(0)

C++取时间戳窗口
摘要:应用场景 防止接口在指定的时间内重复调用,比如 10 秒内不能重复调用。 函数实现 #include <chrono> /// @brief 计算当前时间戳所属时间窗口的起始点(对齐到 Window 秒的整数倍) /// @param Window 时间窗口长度(单位:秒) template <in 阅读全文

posted @ 2025-05-14 15:11 岚天逸见 阅读(52) 评论(0) 推荐(0)

取得std::ifstream对象的文件描述符
摘要:使用C++标准库无法取得std::ifstream对象的文件描述符,但GNU libstdc++库可以取得: #include <fstream> #include <iostream> #include <ext/stdio_filebuf.h> int main() { std::ifstrea 阅读全文

posted @ 2023-09-05 14:18 岚天逸见 阅读(94) 评论(0) 推荐(0)

chatGPT用C++写的HMAC-SHA256函数
摘要:以下内容全为 chatGPT 生成: ```cpp #include #include #include #include std::string hmac_sha256(const std::string &key, const std::string &data) { unsigned char 阅读全文

posted @ 2023-08-15 15:58 岚天逸见 阅读(385) 评论(0) 推荐(0)

C++不同标准兼容性问题集
摘要:* **特化模板兼容性** 下列代码在 c++17 及之前都是可以的,但从 c++20 开始编译报语法错误: ```cpp // g++ -g -std=c++20 -o x x.cpp;./x #include #include template struct X { X(type t) { th 阅读全文

posted @ 2023-07-27 09:42 岚天逸见 阅读(107) 评论(0) 推荐(0)

使用gcc-13.1.0编译安装thrift-0.18.1
摘要:执行 configure 生成 Makefile,排除掉不需要的语言支持和测试等: ```bash ./configure --prefix=/usr/local/thrift-0.18.1 --with-boost=/usr/local/boost --with-libevent=/usr/loc 阅读全文

posted @ 2023-07-25 17:07 岚天逸见 阅读(104) 评论(0) 推荐(0)

一键编译和安装 gcc 脚本
摘要:直接执行即可,执行前需要确保机器上的 wget、gunzip、bunzip2、cmake 可用。 一键编译和安装 gcc 脚本:[install_gcc_tool.sh](https://github.com/eyjian/libmooon/blob/master/shell/install_gcc 阅读全文

posted @ 2023-07-24 19:29 岚天逸见 阅读(187) 评论(0) 推荐(0)

mpc库问题导致gcc编译失败
摘要:使用 mpc-1.3.0 编译 gcc-13.1.0,执行 gcc 的 configure 时遇到如下错误: ``` checking for the correct version of gmp.h... yes checking for the correct version of mpfr.h 阅读全文

posted @ 2023-07-24 15:24 岚天逸见 阅读(533) 评论(0) 推荐(0)

debug方式使用stl
摘要:-D_GLIBCXX_DEBUG 编译时,指定宏 _GLIBCXX_DEBUG 即以 Debug 方式使用 STL 库,效果如下: #include <string> #include <stdio.h> int main(int argc, char* argv[]) { std::string 阅读全文

posted @ 2022-04-25 11:39 岚天逸见 阅读(365) 评论(0) 推荐(0)

编译 thrift-0.14.2 的 C++ 版本
摘要:编译命令: ./configure --prefix=/usr/local/thrift-0.14.2 --with-cpp=yes --with-php=no --with-python=no --with-qt5=no --with-c_glib=no --with-java=no --with 阅读全文

posted @ 2021-09-05 09:54 岚天逸见 阅读(270) 评论(0) 推荐(0)

多线程程序如何简单高效地读取配置中心上的配置?
摘要:本文限定为主动从配置中心读取配置方法,不限定配置中心类型,比如可使用DB作为配置中心。 程序和配置中心间存在网络开销,因此需避免每次业务处理或请求都从配置中心读取配置。 规避网络开销,可采取本地缓存配置,每隔指定时间只读取一次配置中心,比如每秒读取一次配置中心。 假设每秒读取一次配置中心,这样每次的 阅读全文

posted @ 2020-12-18 15:54 岚天逸见 阅读(153) 评论(0) 推荐(0)

C++20新线程 jthread 体验代码
摘要:// C++20新线程 jthread 体验代码 // // 编译(编译本代码,-pedantic 不是必须的): // g++ -std=c++20 -Wall -pedantic -pthread -static-libstdc++ C++20_jthread.cpp -o C++20_jthr 阅读全文

posted @ 2020-09-09 15:20 岚天逸见 阅读(934) 评论(0) 推荐(0)

C++鲜为人知的符号
摘要:目录 目录 1 1. 引言 1 2. 少为人知的符号表1 1 2.1. 符号表 1 2.2. 代码示例 2 3. 少为人知的符号表2 2 3.1. 符号表 2 3.2. 代码示例 3 附:C++的59个关键词列表 3 1. 引言 这些鲜为人知的C++符号,可直接在代码中使用,但实践中不推荐这么做,可 阅读全文

posted @ 2020-07-20 20:27 岚天逸见 阅读(461) 评论(0) 推荐(0)

获取指定目录大小函数源码
摘要:`static __thread off_t dirsize; // 目录大小 static int _du_fn(const char *fpath, const struct stat *sb, int typeflag) { if (FTW_F == typeflag) dirsize += 阅读全文

posted @ 2020-07-20 17:28 岚天逸见 阅读(175) 评论(0) 推荐(0)

将资源文件编译成源代码文件
摘要:目的:简化使用,比如省去了读取配置或者代码中直接大段难以维护的定义。 常用场景:Schema、Lua、SQL等 Linux 自带了资源编译工具 xxd,可将任意文件编译成 c 源代码文件。 常用命令格式: |xxd -i 源文件 目标文件| |--|--| CMake应用示例1(将 test.lua 阅读全文

posted @ 2020-07-20 17:22 岚天逸见 阅读(487) 评论(0) 推荐(0)

CMake 方式编译 gRPC
摘要:首先,下载 gRPC 源代码到本地: git clone https://github.com/grpc/grpc.git 如果只想下载指定版本的,如以版本“1.27.3”为例,可改成如下语句: git clone b v1.27.3 https://github.com/grpc/grpc.git 阅读全文

posted @ 2020-04-01 12:11 岚天逸见 阅读(3584) 评论(1) 推荐(1)

C程序中的raise和kill两个函数有何不同?
摘要:在Linux上执行“man raise”,即可看到两者的区别: 函数raise 函数kill 函数性质 LIBC库函数, raise基于系统调用kill或tgkill(如果内核支持)实现 系统调用,不是LIBC库函数 单线程程序 raise(sig)效果等同kill(getpid(), sig) 多 阅读全文

posted @ 2020-01-16 14:34 岚天逸见 阅读(868) 评论(0) 推荐(0)

运行程序时报错“Value too large for defined data type”
摘要:下列错误,可能是因为在64位上跑32位程序: Value too large for defined data type 此错误对应的出错代码为EOVERFLOW,原因可能是目标文件超过2GB大小。 下列代码可能会导致这个错误出错(为何说是可能,本节最后部分解释): // g++ -g -o x x 阅读全文

posted @ 2020-01-13 15:34 岚天逸见 阅读(3815) 评论(0) 推荐(0)

GLIBC中的库函数fflush究竟做了什么?
摘要:目录 目录 1 1. 库函数fflush原型 1 2. FILE结构体 1 3. fflush函数实现 2 4. fclose函数实现 4 附1:强弱函数名 5 附2:属性__visibility__ 6 1. 库函数fflush原型 先瞧瞧fflush的原型: #include <stdio.h> 阅读全文

posted @ 2019-11-14 12:48 岚天逸见 阅读(1278) 评论(0) 推荐(0)

1 2 3 4 5 ··· 12 下一页

导航