Building with Clang (on Windows) - but for Linux

Sorry about the confusing subject line!! I use Visual Studio 2019 on Windows 10 and I've just installed something called WSL (Windows Subsystem for Linux) which allows it to build apps for Linux. A big part of this involves installing a Linux distro and I've chosen Debian (mostly it just installs basic utilities and a bash shell).

Part of the process involved me issuing this bash command:-

     sudo apt-get install openssh-server g++ gdb gdbserver

After which, I could then build g++ Linux apps - even though I'm running everything in Windows. I then did this:-

     sudo apt-get install clang

So I can now build with clang, as well as g++ - but what about debugging? Should I have also installed a clang debugger? And if so, what would be the apt-get command for that? Thanks,

John

Hi John,

Sorry about the confusing subject line!! I use Visual Studio 2019 on
Windows 10 and I've just installed something called WSL (Windows
Subsystem for Linux) which allows it to build apps for Linux. A big
part of this involves installing a Linux distro and I've chosen Debian
(mostly it just installs basic utilities and a bash shell).

Part of the process involved me issuing this bash command:-

     sudo apt-get install openssh-server g++ gdb gdbserver

After which, I could then build g++ Linux apps - even though I'm running
everything in Windows. I then did this:-

     sudo apt-get install clang

So I can now build with clang, as well as g++ - but what about
debugging? Should I have also installed a clang debugger? And if so,
what would be the apt-get command for that? Thanks,

You can debug programs created by clang with gdb (which you already installed).

Clang has its own debugger (called lldb). It's packaged separately and
you can install it with

  sudo apt-get install lldb

(You can also debug programs created with g++ with lldb. Such is the
power of open standards)

However, I would recommend checking out Visual Studio Code, which can
do remote development (including debugging) on WSL (vscode runs on
Windows, compilers and debuggers run on WSL).

Csaba

Thanks Csaba - yes, I was quite surprised to see Clang working just fine with the gdb debugger!

BTW - I often see Clang described as "llvm" or "cfe" and I've often wondered what they stand for ??

John

BTW - I often see Clang described as "llvm" or "cfe" and I've often wondered
what they stand for ??

LLVM is "Low Level Virtual Machine". That name is a bit confusing, because this isn't the kind of "Virtual Machine" you get from VMWare or the like, but a way of representing programs for a non-existent, hence "virtual," computer architecture. It was created for use in compilers: you have a front-end that translates programming languages into the LLVM representation, and a back-end that generates object files for a specific processor and operating system. That means that to create compilers for X different languages to run on Y different platforms, you only need to write X front-ends and Y backends, rather than X*Y separate compilers. "cfe" is the "C front-end" which also handles C++ and the "Objective" variants of C and C++.

https://en.wikipedia.org/wiki/LLVM

The idea of having a well-defined intermediate representation for compilers and related tools has been around for nearly sixty years (https://en.wikipedia.org/wiki/CPL_(programming_language)) but LLVM seems to be the most successful implementation to date.

Hi John,

BTW - I often see Clang described as "llvm" or "cfe" and I've often
wondered what they stand for ??

Folr LLVM : https://lmgtfy.com/?q=LLVM&pp=1

CFE stands for "C Front-End", a C family (C, C++, Objective C/C++,
etc.) language front-end (https://clang.llvm.org/). It's part of the
LLVM project.

Chris Lattner's first email on cfe-dev
(https://lists.llvm.org/pipermail/cfe-dev/2007-July/000000.html)
already calls it "clang", but "cfe" was the component name in
Bugzilla, the mailing list name, and the directory in Subversion (
http://llvm.org/svn/llvm-project/cfe/trunk/ ).

Csaba

Many thanks guys !!