LLVM实战:如何用Clang+LLVM打造你的第一个C++编译器(附完整配置步骤)

LLVM系列第十六章:写一个简单的编译器 基于LLVM提供的API,用C++写一个很简单的编译器,并用它编译出了我们自己的计算器程序 阅读详情

从零构建C++编译工具链:LLVM与Clang实战指南

第一次接触编译器开发时,我被那些能将高级语言转化为机器指令的神秘工具深深吸引。如果你和我一样,对"编译器是如何工作的"充满好奇,那么亲手搭建一个C++编译环境会是最佳的入门方式。不同于直接使用现成的GCC或Visual Studio,选择LLVM+Clang的组合能让你更清晰地理解编译过程的每个环节——从源代码解析到优化,再到目标代码生成。

1. 环境准备:构建LLVM工具链的基础

在Ubuntu 22.04上配置LLVM开发环境时,我建议直接从官方预编译包开始。相比从源码构建(动辄需要数小时),这种方式能在几分钟内获得可用的工具链:

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16

安装完成后,验证关键组件是否就位:

clang-16 --version
llc-16 --version
opt-16 --version

常见问题排查:

  • 如果遇到ld.lld: error: unable to find library -lc++abi,需要额外安装libc++abi:
    sudo apt install libc++abi-16-dev
    
  • 多版本共存时,使用update-alternatives设置默认版本:
    sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100
    

提示:在生产环境中,建议固定使用特定LLVM版本号而非通用的clang符号链接,避免不同项目间的版本冲突。

2. 第一个C++编译流程剖析

让我们从一个简单的"Hello World"开始,观察完整的编译过程。创建hello.cpp:

#include <iostream>

int main() {
    std::cout << "Hello LLVM!" << std::endl;
    return 0;
}

分阶段执行编译:</

从零开始的LLVM+Clang(一)——下载、配置到第一个pass 从零开始的LLVM+Clang(一)——下载、配置到第一个pass前言一、配置信息二、LLVM+Clang安装方法一:下载预编译包方法二:下载官方源码自行编译1.配置需求2.下载源码3.编译开始方法三:apt-get(不推荐)三、Hello World Pass! 前言 这段时间在给老板打工,学习计划内有个LLVM+clang的学习计划,于是年少无知的我开始倒腾起了这玩意儿,走了很多弯路,也看了不少大佬的资料,最后也有了些自己的心得,所以就把记录的笔记摘抄一下,留作备忘,也供大家参考。 一、配置信息 Win 阅读详情

相关推荐

vscode + llvm-clang 配置优化,函数精准跳转

本文介绍了如何在VSCode中配置LLVM+Clang实现精准函数跳转的方法。首先对比了VSCode自带的C/C++插件在大型项目中存在的跳转精度问题,然后介绍了Clang作为GCC替代品的优势。详细配置步骤包括:安装Clangd插件、下载LLVM工具链、禁用冲突的C/C++扩展、确保CMake编译生成compile_commands.json文件,最后通过重启语言服务器完成配置。文章通过动图展示了使用Clangd后精准跳转的效果,解决了多定义函数跳转和宏隔离代码识别问题,显著提升了大型项目的开发效率。

爱出名的狗腿子 3480

Boost 库使用 Clang LLVM编译器的编译方法

在开始编译 Boost 之前,请确保已经安装了 Clang 编译器,并且版本支持 C++20 标准。同时,从下载所需的 Boost 源码包,并解压到指定目录。

yudaichenydc的博客 1367

C++学习(一八四)clang是什么,与LLVM关系

Clang是一个C语言、C++、Objective-C语言的轻量级编译器。源代码发布于BSD协议下。 Clang是一个由Apple主导编写,基于LLVM的C/C++/Objective-C编译器。 Clang是一个C++编写、基于LLVM、发布于LLVM BSD许可证下的C/C++/Objective-C/Objective-C++编译器。 ......

hankern的专栏 4969

四、windows上配置llvm+clang环境

下载LLVM并安装。下载minGW-w64(

weixin_41080308的博客 2800

从GCC到Clang/LLVM:现代C++编译器生态的演变与实战选择(附VS2022、CMake配置示例)

本文深入探讨了从GCC到Clang/LLVM的现代C++编译器生态演变,对比了两者在性能、标准支持及开发者体验上的差异。通过VS2022和CMake配置示例,指导开发者根据项目需求选择最优编译器,提升跨平台开发效率。

weixin_30296405的博客 494

LLVM Cookbook(高清非打印完整版)

《LLVM Cookbook》以任务驱动的方式,带领读者编写基于LLVM 的编译器前端、优化器、后端。通过丰富的实例,读者能够从中理解LLVM 的架构,以及如何使用LLVM 来编写自己的编译器。 相比于传统的介绍编译技术的书籍,此书更偏向于实战,因此适合熟悉编译但对LLVM 比较陌生的人员,也适合正在学习编译技术并且在寻找实战机会的人员。

Clang+LLVM环境搭建

LLVM+clang环境搭建所用包,亲测可用。包括2.llvm-3.3.src、cfe-3.3.src、clang-tools-extra-3.3.src、compiler-rt-3.3.src、libcxx-3.3.src五个包。

Zemax新手别慌!一文搞懂几何像差:从球差、慧差到色差的实战识别与优化

本文为Zemax新手提供几何像差实战指南,详细解析球差、彗差和色差的识别与优化方法。通过软件操作关键节点和实际项目决策逻辑,帮助光学设计师快速掌握像差诊断与优化技巧,提升光学设计效率。

weixin_42524708的博客 262

SEG-Y 数据介绍及读写

无

1万+

【BUAA】【计组】计算机组成 pre (含详细解析)

BUAA 计算机组成 本文章旨在为@走肖暂时无法接通的系列文章创造一个目录,收藏本文章,方便查阅! 1. 入门测试 2. 基础知识 3. Logisim   欢迎来到 Logisim 的世界   Logisim 门电路   Logisim 组合电路   Logisim 时序电路   Logisim 仿真与调试   应用与挑战 4. Verilog 与仿真工具   前言   ISE 入门   VCS 入门   Verilog 语法   Verilog 题目实例与分析   Verilog 工程的设计开发调试

Schrodinger007的博客 9816

材料仿真软件:Materials Studio_(14).电学性质计算

设置计算参数,包括 k 点网格、交换相关泛函等。

kkchenjj的博客 1870

innovus:sroute 双层follow pin的做法

根据std cellpower pin的层次可以分成两种情况。

m0_61544122的博客 2748

Spring AI 实战(11):收官!10 道面试高频题 + 一张脑图带走全系列

本文是Spring AI系列的收官篇,通过知识脑图梳理前10篇内容,提供面试高频题和避坑清单。主要内容包括: 知识脑图:分6层(核心抽象、输入增强、输出控制等)总结Spring AI全栈技术。 10道高频面试题:涵盖ChatClient/ChatModel关系、结构化输出、RAG链路等核心知识点。 避坑清单:列出9条常见问题及解决方案,如向量维度匹配、Advisor顺序等。 技术对比:分析Spring AI、LangChain4j和Spring AI Alibaba的差异与适用场景。 使用建议:提供面试复习

不才不才不不才的博客 301

Holt-Winters方法预测水电发电量

Holt-Winters 模型, ARMIA,ACF检验 ,Dickey-Fuller 检测,白噪声检测,差分

firefox_yau的博客 1272

泰凌微8258入门教程 基础篇①——Bluetooth® SIG Mesh 快速上手

Bluetooth® SIG Mesh Quick Start

6731

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

深度学习工具包 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")

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

上一篇: 避坑指南:为什么你的WSL装了CUDA 12.9却识别不到GPU?附nvidia-wsl安装详解
下一篇: Kibana索引策略配置避坑指南:为什么你的旧索引无法自动删除(附生命周期策略重置技巧)
sprite
博客等级 码龄26年 129粉丝 1463原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址