Introduction
I wanted to use the clang compiler for a C++ project, using vscode as the IDE;
simples? No!!!
I’m running Ubuntu 20.04, and it seemed the obvious approach was to install the
default llvm tool chain (sudo app install llvm
), write the obligatory “hello
world” program, and go to the vscode debug page and click “create a launch.json
file”. So far so good. Now I hit the play button and I get the error “unable
to find /usr/local/bin/lldb-mi”. WTF?
Now we go down the rabbit hole. You may choose to take the blue pill and move
one, or skip to the solution.
lldb-mi
Googling the error provided some useful facts.
- lldb is the debugger for the llvm tool-chain,
- lldb-mi is an executable which is not part of the base llvm project,
- Ubuntu or llvm have stopped shipping this executable with the llvm package.
Given we are C++ programmers and therefore not lightweight, we choose to build
lldb-mi. After cloning the project
we get an error creating the cmake build file with the default gcc compiler
which complains about lib_lldb
. Google has little to offer here. I bite the
bullet and decide to build the entire llvm tool-chain.
llvm
After cloning llvm and following the build instructions the build starts usinggcc
as the compiler. I notice that 10% of the build has occurred in 10
minutes, so I go for a coffee. At some point the build crashes on my 12 core
64GB machine, as it runs out of memory!
After a little more googling I install the lld
linker and set the build type
to “release” to reduce memory usage. I kick off the build again, and now I get
a compilation error complaining about _Atomic
being undefined. Again googling
doesn’t help much, so I decide to use the llvm tool chain to build itself. After
installing llvm and setting the C and C++ compiler to clang/clang++ I try again
and it works!
lldb-mi revisited
Using my compiled llvm tool chain I can successfully compile lldb-mi
, and
vscode now allows me to debug my program. Superb!
Solution
Install the llvm tool chain with the lld
linker. Also use ninja
instead ofmake
(cmake
should be installed already).
1 | sudo apt install lld |
Clone llvm and build it. I used version 12.
1 | git clone --depth 1 --branch release/12.x git@github.com:llvm/llvm-project.git |
Build lldb-mi:
1 | git clone git@github.com:lldb-tools/lldb-mi.git |
Assuming you have the tool-chain on your path:
1 | export PATH=$HOME/local/lvmm-12.0.0/bin:$PATH |
The vscode generated files looked like this:
launch.json
1 | { |
tasks.json
1 | { |
Epilogue
It’s a day of my life that I won’t get back, but I’m loving the speed of the
compiler and the more sensible error messages.