![]() Replace the content of the tasks.json with the following code: with the correct path. If you have already a running project, you can create this file by yourself. Therefore, to configure/create it in a new project, press Ctrl+Shift+B and follow the prompts until you get to "Others" (see Fig. The task is usually defined in a tasks.json file inside the. Building C++ in a container with VS Codeįirst, let’s configure a building task. Therefore, you need to be inside the source code folder while you run this command, or you can change the $PWD value with a full path to the source directory. The -v parameter creates a bind mount that maps the local file system ( $PWD - print working directory) into the container ( /source). As debugging requires running privileged operations, you'll run the container in unconfined mode, thus the -security-opt set to seccomp:unconfined. The -p parameter links the port 2222 to the exposed 22 port of the container. The -d parameter detaches the Docker container from the terminal. To run a container based on this image so that VS Code can debug processes in it, type the following on a terminal inside the folder, in which your source code is located: docker run -d -p 2222:22 -security-opt seccomp:unconfined -v $PWD:/source -name gdb-cpp-image gdb-cpp-image ![]() The image will be built with a name gdb-cpp-image. To build this image, type the following on a terminal inside the folder, in which you created the Dockerfile file: docker build -t gdb-cpp-image. The following lines install and enable SSH with user and password root:root and expose the port 22. The second one includes the libraries required for my C++ application. The first one is required to remotely build and debug applications. In this case, for example, you see that I included two apt-get install -y lines. You should consider that this Docker image should have all libraries that you need to compile your application. I like to use Debian images because of Debian simplicity. & sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \ # configure SSH for communication with Visual Studio Libncurses5-dev libncursesw5-dev libasio-dev libboost-all-dev RUN apt-get install -y libopenblas-dev liblapack-dev python3-dev \ & apt-get install -y g++ build-essential make cmake gdb gdbserver \ # install build dependencies to build and debug LABEL description="Container for use with Visual Studio" Creating a container to use with VS CodeĬreate a Dockerfile inside a folder and add the following in that file: FROM debian:bullseye If you need some help to install extesions on VSCode, please follow the official tutorials. To compile and debug applications on VSCode, you should install the following extensions: You'll need to setup a launch task that will debug the application.You'll need to setup a task that will compile the application code.This container will be accessed via SSH to compile the application A container will be started using this image and the source code will be linked using the volume option of Docker. You need to build a Docker image with the tools/dependencies/libraries etc.The steps are divided in three main groups: This article is a documentation for me that I will use every time that I need to compile a C++ application. I found that VSCode has the capability to target a container for application building and/or debugging :). Last week, I was working on a C++ application on a remote machine in the cloud, and I didn't want to install all the compiling and debugging tools/libraries/dependencies on the host OS, but I wanted to have all of them in a container. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |