Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/christiankuehnel/cpp-on-win
Tutorial for developing C++ on Windows using open source tools.
https://github.com/christiankuehnel/cpp-on-win
clang clangd cmake cpp cxx ninja vscode windows
Last synced: about 1 month ago
JSON representation
Tutorial for developing C++ on Windows using open source tools.
- Host: GitHub
- URL: https://github.com/christiankuehnel/cpp-on-win
- Owner: ChristianKuehnel
- Created: 2020-12-14T09:05:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-17T15:57:36.000Z (about 4 years ago)
- Last Synced: 2024-10-19T07:11:38.271Z (3 months ago)
- Topics: clang, clangd, cmake, cpp, cxx, ninja, vscode, windows
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Developing C++ on Windows
This tutorial will walk you through installing and configuring widely used
C++ development tools on Windows.## Tool Overview
We will be using these tools as they are widely used in open source development:
* [Cmake](https://cmake.org/) - as build management system
* [Ninja](https://ninja-build.org/) - as build system actually doing the building
* [LLVM](http://llvm.org/) - as compiler (clang) , linker (lld), debugger (lldb),
language server (clangd)
* [git](https://git-scm.com/) - as version control tool (e.g. to work on Github)While not really required, I would recommend using an integrated development
environment. IMHO this makes using all these tools much easier. In this tutorial,
we'll be using [Visual Studio Code](https://code.visualstudio.com/) from Microsoft (short VSCode).
While not 100% open source, it has hughe ecosystem of extensions available and
also works across many operating systems and languages.## Installation
To make installation as easy as possible, we'll be using
[Chocolately](https://chocolatey.org/) as package manager to install the tools
we need:1. Install chocolately using admin rights follinging these instructions:
https://chocolatey.org/install1. In a Powershell *with admin rights* run:
```choco install -y cmake ninja llvm git vscode git```
to install the tools we will need, the argument `-y` tells it to assume `yes`
on all questions during the installation.That's it.
## Configuring VSCode
Now that we have all the tools installed, we need to configure them. We will do
this by configuring a first project to see if everything is working.1. Start Visual Studio Code and install these extensions:
* [clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd),
the C++ language server from LLVM.
* [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools),
to configure the builds from within VSCode
1. Disable the C++ Intellisense extension, it will interfere with clangd.
If there is a pop-up, decline it, even if VSCode keeps asking you over and
over again. We'll be using `clangd` instead.
1. On the "Welcome" screen of Vistual Studio Code select "clone repository..."
and enter `https://github.com/jameskbride/cmake-hello-world` as URL. Then pick
a local folder where you want to store that project.
1. Allow Cmake to configure the project. When asked to select a "Kit" choose
"Clang". This will select clang & Co as your toolchain for this project.
1. To run something in VSCode, hit ` + +`. This will open the
"Command Palette". Use the Command Palette to run the followingn commands:
1. Run `> CMake: configure` to configure the build environment. The Terminal
will show you the log output of the CMake commands. If you see
`Generating done` in the log, the configure step was successful.
1. Run `> Cmake: build` (or hit ``) to build the project. Again you will see
the log output of the compilation in the Terminal. If your system is be using
Ninja as builder, `The build completed with exitcode 0.` means that the build
was successful.
1. Run `> CMake: run without Debugging` (or hit ` + `). This will run
your program in the Terminal and show you the console output. If you see the
output `Hello, world!` your program was run successfully.That's it. You just downloaded a project from Github, configured CMake, compiled
and linked the project and were able to run the resulting program.## Running the debugger
1. Install the
[CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)
extension from the marketplace.
1. Configure the target you want to debug:
```json
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build/",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
```
1. Start the debugger with ``. When asked which "environment" to use
select `LLDB` from the list.That's it, now you can debug your C++ project in VSCode. More information on
debugging in VSCode can be found in the
[manual](https://code.visualstudio.com/docs/editor/debugging).## TODO: Unit testing
using GTest