VScode 中 Clangd 使用:把 compile_commands.json 与索引路径改到 TaoToken 的配置实践

1. 为什么大型 C/C++ 项目里 Clangd 更值得折腾

如果你在 VScode 里打开过一个几十万行的 C/C++ 工程,大概率经历过这种场面:装完 C/C++ 插件,内存直接飙到几个 G,改一行代码风扇狂转,符号跳转要等好几秒。我试过在一台 16G 内存的机器上开一个中型嵌入式项目,C/C++ 插件的索引进程吃掉将近 3G,编辑器卡到打字都延迟。换成 Clangd 之后,同样的工程内存占用降到几百兆,跳转反而更准。这就是为什么很多人愿意忍受 Clangd 稍微繁琐的配置门槛。

Clangd 是什么?简单说,它是基于 LLVM/Clang 的 C/C++ 语言服务器,通过 LSP 协议给 VScode 提供补全、跳转、诊断、格式化能力。它不依赖 VScode 的 C/C++ 插件那套 Tag Parser,而是直接读编译数据库 compile_commands.json,按真实编译参数去解析每个文件。所以它「懂」你的 -I 头文件路径、-D 宏定义、-std 标准版本,跳转和补全的准确度天然更高。适合谁?适合中大型工程、跨平台工程、用 CMake 或 Makefile 构建、对编辑器资源占用敏感的同学。小项目用 C/C++ 插件确实更省事,但工程一大,Clangd 的优势就压不住了。

这篇要解决的核心问题有三个:第一,compile_commands.json 怎么稳定生成,尤其是老 Makefile 工程;第二,VScode 的 settings.json 里 Clangd 参数怎么配,包括编译数据库目录、索引缓存路径、后台索引策略;第三,索引缓存和编译数据库路径怎么统一管理,避免每个工程重复配置、缓存到处乱放。同时我会把模型侧和 API 侧的接入配置一起给出来,方便你在写代码时顺手用 TaoToken 的模型对话做代码解释、报错分析,两边配置互不干扰。

需要先说明一点:Clangd 本身是本地语言服务器,不联网也能工作;TaoToken 提供的是模型 API 与编码计划能力,两者是「本地索引 + 云端辅助」的配合关系,不是替代关系。你把 Clangd 配好,跳转补全在本地跑;遇到看不懂的模板报错、想让它解释一段编译参数,再通过 API 调用模型。下面按「先本地、后接入」的顺序走。

2. 前置准备:Clangd 安装、compile_commands.json 与 TaoToken 接入信息

这一节把三件事一次说清:Clangd 怎么装、编译数据库怎么来、TaoToken 的接入信息放哪。三件事都准备好,后面的配置片段才能直接复制。

先说 Clangd 安装。Ubuntu 20.04 的源里 clangd 版本偏旧,装 12 版本可能要降级 gcc,不划算。直接下官方 release 的可执行包更省心:从 LLVM 的 GitHub Release 页面下载 clangd-linux-*.zip,解压后把 bin/clangd 拷到 /usr/local/bin,lib 目录下的库拷到 /usr/local/lib,然后 sudo ldconfig 刷新一下。验证:

clangd --version
# 期望输出类似:
# clangd version 18.1.3
# Features: linux+grpc
# Platform: x86_64-unknown-linux-gnu

能打印版本号就说明装好了。VScode 侧在扩展市场搜 clangd,装官方那个(作者 LLVM),装完先别急着开工程,把下面的配置写完再打开,否则它会用默认参数先索引一遍,白跑一次。

再说 compile_commands.json。CMake 工程最省事,配置时加一个开关:

cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

或者在 CMakeLists.txt 里写 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)。生成的文件在 build/compile_commands.json。Makefile 老工程没有现成开关,用 bear 包一层:sudo apt install bear,然后在原来编译命令前加 bear,比如 bear -- make -j8,就会在工程根目录生成 compile_commands.json。它的结构长这样,每条记录一个源文件的完整编译参数:

[
  {
    "directory": "/home/user/proj/build",
    "command": "/usr/bin/gcc -I../include -DDEBUG -std=c11 -c ../src/main.c",
    "file": "../src/main.c"
  }
]

注意 directory 是编译时的工作目录,file 可能是相对路径,Clangd 会按 directory 去解析,所以这个文件别随便挪位置,挪了要保证相对关系不变。

最后是 TaoToken 的接入信息。注册后在控制台拿 API Key,Base URL 用 https://taotoken.net/api,模型 ID 按你选的填。这三件套(Base URL + Key + Model ID)后面在 VScode 里配模型辅助时会用到。相关入口:

官网:https://taotoken.net/?utm_source=taotoken_aicg_blog_end&utm_medium=csdn&utm_campaign=rewrite API:https://taotoken.net/api 控制台取 Key:https://taotoken.net/console?utm_source=taotoken_aicg_blog_end&utm_content=console&utm_campaign=rewrite API Keys 管理:https://taotoken.net/api-keys?utm_source=taotoken_aicg_blog_end&utm_content=api-keys&utm_campaign=rewrite

把 Key 存到环境变量里,别硬编码进配置文件:export TAOTOKEN_API_KEY="sk-...",写进 ~/.bashrc 或 ~/.zshrc。这样 VScode 里的插件读环境变量就行,配置文件可以放心提交到仓库。

3. 可复制配置:settings.json 与 .clangd 片段

这一节是全文的核心,所有片段都可以直接复制。分三层:VScode 的 settings.json 管 Clangd 启动参数和缓存路径;工程根的 .clangd 管这个工程特有的编译数据库位置和补全行为;模型辅助部分单独放一个配置块,和 Clangd 解耦。

先看 settings.json。打开 VScode 命令面板,Preferences: Open User Settings (JSON),把下面这段合并进去。关键参数我逐行注释了作用:

{
  "clangd.path": "/usr/local/bin/clangd",
  "clangd.arguments": [
    "--compile-commands-dir=${workspaceFolder}/build",
    "--background-index",
    "--background-index-priority=normal",
    "--clang-tidy",
    "--completion-style=detailed",
    "--header-insertion=iwyu",
    "--pch-storage=memory",
    "--log=info",
    "--query-driver=/usr/bin/gcc,/usr/bin/g++,/usr/bin/clang*"
  ],
  "clangd.onConfigChanged": "restart",
  "clangd.checkUpdates": false,
  "clangd.detectExtensionConflicts": true,
  "clangd.fallbackFlags": [
    "-std=c++17",
    "-I${workspaceFolder}/include"
  ]
}

几个参数值得展开。--compile-commands-dir 指定编译数据库目录,默认 Clangd 会在工程根找,但 CMake 工程通常在 build/ 下,所以显式指过去。--background-index 开启后台索引,大工程第一次打开会慢慢建索引,别关。--query-driver 很重要:Clangd 需要知道用哪个编译器去查询系统头文件路径,不配的话标准库头文件可能跳不过去,报「找不到 vector」这类错。--pch-storage=memory 把预编译头放内存,速度快但吃内存,机器紧张可以改 disk。

索引缓存路径默认在 ~/.cache/clangd/index,工程多了会堆很大。想统一挪到某个盘,用环境变量控制,在 settings.json 里加:

{
  "clangd.arguments": [
    "--compile-commands-dir=${workspaceFolder}/build",
    "--background-index",
    "--query-driver=/usr/bin/gcc,/usr/bin/g++"
  ],
  "terminal.integrated.env.linux": {
    "CLANGD_INDEX_DIR": "/data/cache/clangd-index"
  }
}

更稳的做法是在 shell 启动文件里设 export XDG_CACHE_HOME=/data/cache,Clangd 会跟着把索引放到 /data/cache/clangd/index。这样所有工程共用一套缓存根目录,清理时直接删目录,不用满硬盘找。

再看工程根的 .clangd 文件。它管单个工程的覆盖配置,优先级高于全局参数:

CompileFlags:
  CompilationDatabase: build/
  Add:
    - -DDEBUG=1
    - -Iinclude
  Remove:
    - -Werror
    - -march=native
Diagnostics:
  ClangTidy:
    Add:
      - modernize-*
      - bugprone-*
    Remove:
      - modernize-use-trailing-return-type
Index:
  Background: Build
  StandardLibrary: true
Completion:
  AllScopes: true
  HeaderInsertion: iwyu

CompilationDatabase 写相对工程根的路径,等价于命令行参数,但跟着工程走,换机器不用改 settings.json。Remove 里去掉 -Werror 和 -march=native 是常见操作:前者会让 Clangd 把警告当错误标红,后者在跨机器时可能不被支持,导致解析失败。Index.StandardLibrary: true 让标准库也进索引,跳 std::vector 更顺。

最后是模型辅助的配置块,和 Clangd 完全独立。如果你用 Continue 或 Cline 这类插件,配置里填三件套:

{
  "models": [
    {
      "title": "TaoToken",
      "provider": "openai",
      "model": "claude-sonnet-4-20250514",
      "apiBase": "https://taotoken.net/api",
      "apiKey": "${env:TAOTOKEN_API_KEY}"
    }
  ]
}

apiBase 用 https://taotoken.net/api,不要带多余路径;apiKey 走环境变量引用,别写明文。模型 ID 按控制台里实际可用的填。这样你在编辑器里选中一段 Clangd 报的模板错误,右键让模型解释,走的是这条通道,和本地索引互不影响。

4. 验证请求:符号跳转、日志确认与模型侧连通性

配置写完必须验证,不然你以为生效了,其实 Clangd 还在用默认参数瞎跑。验证分三步:看 Clangd 日志确认参数生效、做一次符号跳转确认索引可用、再测一次模型 API 连通性。

第一步,看日志。VScode 里 Ctrl+Shift+P 执行 Clangd: Show Output,或者直接打开输出面板选 clangd 通道。正常启动会打印类似:

I[10:21:33.102] clangd version 18.1.3
I[10:21:33.110] arguments: /usr/local/bin/clangd --compile-commands-dir=/home/user/proj/build --background-index ...
I[10:21:33.245] Loaded compilation database from /home/user/proj/build/compile_commands.json
I[10:21:33.246] Parsing compilation database: 128 entries
I[10:21:34.001] Indexed /home/user/proj/src/main.c (12 symbols)

重点看两行:Loaded compilation database from ... 确认路径对不对,Parsing compilation database: N entries 确认条目数和你工程源文件数量对得上。如果显示 Failed to find compilation database,说明路径错了,回第 3 节检查 --compile-commands-dir。如果条目数是 0,说明 compile_commands.json 是空的或者格式坏了,重新生成。

第二步,符号跳转。打开一个 .c 或 .cpp 文件,把光标放到某个函数调用上按 F12,能跳到定义就说明索引生效。再试 Ctrl+Click 跳头文件里的结构体,能跳过去说明 --query-driver 配对了。如果跳转失败但日志显示索引正常,多半是那个文件不在编译数据库里,检查 compile_commands.json 是否覆盖了它。

第三步,模型侧连通性。用 curl 直接打一次 API,确认 Key 和 Base URL 没问题:

curl -s https://taotoken.net/api/v1/chat/completions \
  -H "Authorization: Bearer $TAOTOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "messages": [{"role": "user", "content": "用一句话解释 gcc 的 -I 参数"}],
    "max_tokens": 100
  }'

返回里有 choices[0].message.content 就说明通了。如果返回 401,是 Key 错了或没带 Bearer;返回 404,检查 apiBase 是不是写成了 https://taotoken.net/api/v1 又拼了一次 /v1。这一步通了,编辑器插件里同样的三件套就能用。

验证完记得做一件事:把 ~/.cache/clangd/index 或你自定义的缓存目录大小看一眼,du -sh 一下,心里有数。大工程索引几个 G 很正常,磁盘紧张就定期清。

5. 常见报错排查:401、local proxy failed、reading choices 与 OAuth

配置过程中踩的坑基本集中在几类报错上,这一节按真实报错信息对照排查。先声明:下面这些报错是配置层面的常见现象,排查思路是「先看日志、再对参数、最后查网络与凭据」。

第一类,401 Unauthorized。出现在模型 API 调用时,原因通常是 Key 没读到或格式不对。检查 echo $TAOTOKEN_API_KEY 有没有值,VScode 是从启动它的 shell 继承环境变量的,如果你在改完 ~/.bashrc 后没重启 VScode,插件读到的还是旧环境。解决:完全退出 VScode 再开,或者用 code . 从终端启动。另外确认请求头是 Authorization: Bearer sk-...,少个空格都会 401。

第二类,local proxy failed 或连接超时。这类报错一般和本机网络环境有关,排查方向是 DNS 解析和出口连通性,不是配置语法问题。先用 curl -v https://taotoken.net/api 看握手到哪一步断的,能拿到 TLS 握手就说明域名可达。如果公司网络有出口限制,找网管确认白名单,别在配置文件里乱加代理参数,容易越配越乱。

第三类,Error reading choices 或返回体解析失败。这通常不是网络问题,而是返回的 JSON 结构和插件预期不一致。常见原因:apiBase 多写了 /v1 导致请求打到错误路径,返回一个 HTML 错误页,插件按 JSON 解析就报 reading choices。解决:apiBase 严格用 https://taotoken.net/api,让插件自己拼 /v1/chat/completions。还有一种情况是模型 ID 写错,服务端返回错误对象,插件同样解析失败,对照控制台里的模型列表核对。

第四类,OAuth 相关报错,比如 OAuth token expired 或授权回调失败。如果你用的是需要 OAuth 登录的编码工具(比如某些 CLI 编码助手),token 过期就重新走一次授权流程,别手动改 token 文件。授权回调地址要和工具文档一致,端口被占用会导致回调失败,换个端口重试。

第五类,Clangd 侧的 Failed to find compilation database 和 Unknown argument。前者回第 3 节检查 --compile-commands-dir 和 .clangd 里的 CompilationDatabase;后者是 compile_commands.json 里有 Clangd 不认识的编译参数,在 .clangd 的 CompileFlags.Remove 里加通配去掉,比如 -fno-* 这类厂商私有参数。

排查顺序建议固定下来:先看输出面板的 clangd 日志,再看模型插件的日志,最后用 curl 单独验证 API。三层分开看,别混在一起猜。

6. 长期编码与 Agent 场景:把模型能力接进日常流程

Clangd 解决的是「本地代码理解」,但日常开发还有大量「解释、生成、重构」的需求,这部分交给模型更合适。TaoToken 的 Coding Plan 就是为长期编码场景准备的,适合每天都要和模型来回几十轮的人,比按次调用更划算。入口在这:

Coding Plan:https://taotoken.net/coding-plan?utm_source=taotoken_aicg_blog_end&utm_content=coding-plan&utm_campaign=rewrite 模型对话:https://taotoken.net/chat?utm_source=taotoken_aicg_blog_end&utm_content=chat&utm_campaign=rewrite 接入文档:https://taotoken.net/doc?utm_source=taotoken_aicg_blog_end&utm_content=doc&utm_campaign=rewrite

具体怎么配合?举几个我常用的场景。场景一:Clangd 报了一个模板展开错误,报错信息几十行,选中复制,丢给模型对话,让它提炼「真正的原因是哪一行」。场景二:读一个老工程的 Makefile,让模型把编译参数翻译成人话,顺便对照 compile_commands.json 检查有没有漏掉的头文件路径。场景三:写单元测试时,让模型根据函数签名生成测试骨架,你再手动补断言。这些都不需要模型直接连你的生产库或代码仓库,你把片段贴过去就行,安全边界清晰。

如果你用 Claude Code 这类 CLI 编码工具,接入配置也是三件套。以环境变量方式为例:

export ANTHROPIC_BASE_URL="https://taotoken.net/api"
export ANTHROPIC_AUTH_TOKEN="$TAOTOKEN_API_KEY"
export ANTHROPIC_MODEL="claude-sonnet-4-20250514"

配完跑一次 claude --version 和一次简单对话确认连通。注意 ANTHROPIC_BASE_URL 只写到 /api,不要带 /v1。这套配置和 VScode 里的 Clangd 完全独立,互不干扰,你可以一边用 Clangd 跳转,一边在终端里让 CLI 工具改代码。

最后给一个实用技巧:把 Clangd 的索引缓存目录和模型工具的日志目录都放到同一个数据盘,比如 /data,定期用 du -sh /data/* 看一眼谁在膨胀。索引缓存大了清掉重建就行,日志大了直接删。工程配置用 .clangd 跟着仓库走,个人偏好用 settings.json 跟着机器走,模型凭据用环境变量跟着 shell 走,三层分离,换机器换工程都不慌。

相关推荐

Palantir解密:说人话,到底什么是“本体”?

笔者2018年在云计算公司开展政企数字化专项时,便意识到全面数字化进程背后存在大量未知领域,尤其是未来数字世界的底层架构如何构建这一关键问题。可惜因为种种原因,连那几个小专项最终都未能落地,也就无从深入了。近期看了很多有关Palantir的材料,倒觉得这像是新硅谷(区别于比尔盖茨、扎克伯格等主导的硅谷时代)交出的一份关于“数字世界底层架构”的答案,至于这个答案是否成立、有没有更优解、我们本土对标的版本是什么,可能都还待看。《Palantir解密》系列尝试通过解析Palantir,来系统回答这一问题。

SZSDQJC的博客 2165

Bear+Clangd+Vscode+Ubuntu索引linux代码:把compile_commands.json改到TaoToken统一Key通道

Ubuntu 下用 Bear 包住 make 采集 compile_commands.json,配合 Clangd 与 VSCode 索引 Linux 内核代码,并移除 -mabi=lp64 解决编译器实例报错;同时把多工具 Base URL 与 Key 收敛到 TaoToken 统一通道,配置只维护一份。官网:https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_42609225的博客 120

测试人必看!正交表与Allpairs工具对比:如何选择最适合你的组合测试方案?

本文深入对比了正交表、PICT与Allpairs三种主流组合测试方案,帮助测试人员根据项目场景做出最佳选择。文章分析了各自的核心原理、优劣势及适用场景,特别强调了在涉及复杂约束时PICT工具的强大功能,并提供了从原理学习到CI/CD集成的实战选型指南。

weixin_29224309的博客 271

VScode 中 Clangd 配 TaoToken:settings.json 骨架与报错排查

在 VScode 里用 Clangd 替代 C/C++ 插件,先写对 settings.json 骨架:指定 clangd.path、--compile-commands-dir 与 --query-driver,并关闭 C_Cpp.intelliSenseEngine。模型请求统一走 TaoToken 的 Key/API 通道,Key 存环境变量,官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 可创建与管理。

weixin_42599908的博客 84

图像相似度的评价指标 : FID(Fréchet Inception Distance)

FID(Fréchet Inception Distance) 是用来计算真实图像与生成图像的特征向量间距离的一种度量。如果FID值越小,则相似程度越高。最好情况即是FID=0,两个图像相同。 实际计算: 参考链接:https://machinelearningmastery.com/how-to-implement-the-frechet-inception-distance-fid-from-scratch/ # example of calculating the frechet inceptio

weixin_43723625的博客 1万+

【SPSS实战】手动实现Quade非参数协方差分析:从数据准备到结果解读

本文详细介绍了在SPSS中手动实现Quade非参数协方差分析的实战方法。当数据不满足正态分布等参数检验假设时,通过将协变量和因变量转换为秩,并利用秩回归残差进行Kruskal-Wallis组间比较,提供了一种清晰、可操作的近似解决方案。该方法有效解决了非正态数据的协变量调整问题,适用于实验研究和调查数据分析。

bean的博客 469

Cursor(VSCode) + clangd 无法跳转 Qt 类/变量:把 compile_commands.json 改到 TaoToken 的排查路径

Cursor/VSCode 里 clangd 对 Qt 类跳转失效,多半是 compile_commands.json 缺失或路径错位。本文给出 CMake/qmake 生成编译数据库、.clangd 补 Qt 宏、settings.json 指定 --compile-commands-dir 的可复制步骤,并用 TaoToken 统一 Key/API 通道做环境自检,把索引问题与通道问题分开验证。官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_

weixin_42113456的博客 211

国家大地2000坐标系投影坐标转高德地图经纬度坐标-【高斯投影坐标】

国家大地2000坐标系投影坐标转换成高德经纬度坐标显示画图。

devil_zhuzhu的博客 1万+

VSCode里clangd跳转配置:从compile_commands.json到TaoToken统一Key

VSCode里clangd跳转失效,先查compile_commands.json是否生成、--compile-commands-dir是否指对,再关掉C/C++插件IntelliSense避免抢文件。本文给出可复制的settings.json与.clangd片段,并把AI插件模型请求统一到TaoToken一个Key,官网见https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_35756624的博客 83

linux上使用tun/tap设备模拟一个虚拟网卡,并将该虚拟网卡连接到新创建的网桥上

tun/tap设备是操作系统内核中的虚拟网络设备,是用软件模拟的网络设备,提供与硬件网络设备完全相同的功能。主要用于用户空间和内核空间传递报文。tun/tap对于硬件网络设备而言,一端连接的是物理网络,一端连接的是网络协议栈。对于tun/tap设备而言,一端连接的是应用程序(通过 字符设备文件),一端连接的是网络协议栈。

糖果墙的博客 6415

Python编程基础05:运算符与表达式

文章目录一、算术运算符1、分类说明表2、注意事项3、案例演示任务1、计算成绩差与平均成绩课堂练习:编程处理带余除法。任务2、打印购物小票 运算符就是专门用于告诉程序执行特定运算或逻辑操作的符号。表达式是指由常量、变量和运算符组成的一个算式。编写程序对数据进行处理,其实处理就是对数据实施各种各样的运算,搞懂运算符与表达式是我们编写程序的基础性工作,本次讲课笔记通过案例讲解各种运算符的用法以及正确书写Python表达式的注意事项。 一、算术运算符 Python中的算术运算符就是用来处理四则运算的符号,也是

howard2005的专栏 3122

Codex 跑 clangd 索引排查:Key 用 TaoToken

Codex 排查 clangd 不读 compile_commands.json 时,类成员标红、跳转失灵往往不是编译错误,而是索引失效。本文从 clangd 日志、.vscode/settings.json 和 .clangd 配置逐层拆解,并教你用 TaoToken 给 Codex 配好模型通道:在 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 创建 Key,把 Base URL 填入 ~/.codex/config.toml,用统一 A

weixin_42527665的博客 184

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

VSCode / Trae 搭建 STM32CubeMX 开发环境:插件配置、编译与调试流程(TaoToken 统一 Key 接入版)

用 tasks.json 与 launch.json 打通 STM32CubeMX 工程的编译烧录调试,先 Configure 再 Build 让 clangd 读到 compile_commands.json。TaoToken 统一 Key 接入 AI 插件,附 401、local proxy failed、reading choices 等报错排查,官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_42609225的博客 13

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

VSCode里clangd跳转失效?从compile_commands.json到TaoToken的排查路径

VSCode 里 clangd 跳转失效,先查 compile_commands.json 是否生成并被正确加载。本文从 CMake 导出配置讲到 clangd 参数写法,再用 TaoToken 统一 Key 验证 API 通道,附常见报错排查。详见 https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_35752645的博客 12

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

vscode clangd 保姆教程:把 compile_commands.json 与 clangd 配置改到 TaoToken 统一通道

VS Code 里 clangd 补全跳转失灵,多半是 compile_commands.json 路径与 --query-driver 没对齐。本文给出可复制的 settings.json、.clangd 与 .clang-format 片段,并演示把模型辅助请求统一到 TaoToken 通道,含 401、local proxy failed 等报错排查。详见 https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_42602368的博客 17

mac vscode 使用 clangd 总报错?把 compile_commands.json 改到 TaoToken 统一通道

macOS 上 VS Code 用 clangd 总报错,先跑 cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 生成 compile_commands.json,再在 settings.json 里用 --compile-commands-dir 指向 build 目录,跳转与补全即可恢复。模型补全等能力统一走 TaoToken 通道,官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_e

weixin_42613017的博客 6

compile_commands.json 报错,让 Codex 走 TaoToken 兼容通道排查 clangd 补全行不行

compile_commands.json 报错使 OpenHarmony rk3568 的 clangd 代码补全失效。让 Codex 接 TaoToken 兼容通道,核对 out/rk3568 落点与软链接排查。Key 入口 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 。

weixin_35749796的博客 8

vscode 插件 clangd 配置总出错?把 settings.json 改到 TaoToken 统一通道

VS Code 里 clangd 报 local proxy failed 或 401,多半是 settings.json 残留旧代理地址。把 clangd 增强请求的 Base URL、Key、Model ID 统一改到 TaoToken 通道,重启语言服务器看日志确认 200 即可恢复补全。官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_42601134的博客 118

解决clangd无法识别C++(CMake)项目外头文件的问题:Windows下Cursor与VSCode的TaoToken配置实践

Windows下CMake项目clangd无法跳转外部头文件?在CMakeLists.txt加set(CMAKE_EXPORT_COMPILE_COMMANDS ON)生成编译数据库,配合.clangd与全局config.yaml补-I路径即可恢复跳转补全。文中同步给出Cursor/VSCode接入TaoToken的Base URL与Key配置,官网:https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_34779181的博客 8

rk3588s 上 vscode 索引失败:用 TaoToken 统一 Key 打通 clangd 配置

RK3588S 上 VS Code 的 clangd 报 write EPIPE 索引失败,多因 compile_commands.json 路径或编译参数不匹配。本文给出可复制的 settings.json 与 .clangd 配置,并用 TaoToken 统一 Key 管理模型辅助入口,官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 可查接入文档。

weixin_35756130的博客 10

Cursor/Trae/VSCode 的 C++ 跳转失效排查:从 compile_commands.json 到 TaoToken 统一通道

Cursor/Trae/VSCode 的 C++ 跳转失效,先查 compile_commands.json 是否生成、clangd 索引是否跑完,再把 AI 补全端点统一到 TaoToken 复测。本文给出 cmake/bear 生成命令、.clangd 配置、三件套 Base URL/Key/Model ID 写法,并对照 401、local proxy failed、reading choices 等报错逐项排查。官网:https://taotoken.net/?utm_source=taotoken

weixin_35755640的博客 9

VsCode 中 clangd 插件配置全解:从 msys2 到 clang-format 的 TaoToken 实践

在 VsCode 中用 msys2 装好 clangd 后,把 clangd.path 指向 clang64 下的二进制并加 --query-driver,即可解决标准库飘红。本文给出可复制的 settings.json、.clang-format 与 compile_commands.json 配置,并演示用 TaoToken 官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 的 API 辅助排查 clangd 报错。

weixin_42608318的博客 8

【经验】Ubuntu 离线装 VsCode 插件读 Linux kernel 源码:TaoToken 统一 Key 配置骨架

Ubuntu 离线装 VsCode 插件读 Linux kernel 源码,用 bear 生成 compile_commands.json 让 clangd 精准跳转,再通过 TaoToken 统一 Key 配置骨架集中管理 AI 能力。官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end 提供接入地址与文档,curl 验证 Key 生效即可。

weixin_35757531的博客 13

搭建Linux源码阅读环境:用TaoToken统一Key打通VSCode+clangd编译索引链路

用 bear 生成 compile_commands.json 后,clangd 才能正确索引 Linux 内核源码。本文按准备源码、生成编译数据库、配置 clangd、接入 TaoToken 统一 Key、验证跳转、排查 401 与代理报错的顺序,给出可直接复制的命令与配置,打通 VSCode 源码阅读链路。详见 https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_35755640的博客 7

rk3588s 上 vscode 索引失败:用 clangd 重建索引并接入 TaoToken 的排查大纲

RK3588S 上 VS Code 索引失败常报 EPIPE,根因是 clangd 缺少 compile_commands.json。本文用 bear 重建编译数据库,配合 --query-driver 与远程 settings.json 恢复跳转,并接入 TaoToken 辅助分析日志。详见 https://taotoken.net/?utm_source=taotoken_aicg_blog_end

weixin_36012152的博客 123

WSL + VScode 上用 LLVM + Clangd + LLDB 高效编程 C++:把工具链配置改到 TaoToken 的实操大纲

在 WSL + VScode 中配置 LLVM + Clangd + LLDB 的 C++ 工具链,核心是生成 compile_commands.json 并正确设置 --query-driver。本文提供从 apt 安装、settings.json 全量片段到断点调试的实操步骤,同时将模型调用统一接入 TaoToken 官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end ,实现补全、跳转、调试与 AI 辅助同一入口。

weixin_42610010的博客 9
上一篇: 模型选型与成本控制上手:Sonnet vs Haiku 生产级压测与场景匹配指南(TaoToken 统一 Key 接入版)
下一篇: Windows 零基础安装 Claude Code 全流程:Node.js 环境、ERR_BAD_REQUEST 网络报错与 cc-switch 第三方 API 避坑指南(含 TaoToken 配置)
Lemaden
博客等级 码龄8年 2511粉丝 3368原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址