Tags

2 pages

Cmake

VS Code for C++, don't forget CMake and GDB Printer

Previously, when I debugged C++ in VS Code, the configuration basically stopped at launch.json, maybe with an extra line for GDB. Fill in the program, fill in the gdb, set the breakpoints. And then what? Then every time before debugging, I had to manually run cmake --build in the terminal. What was even more annoying was that after setting breakpoints on custom prices, contracts, or order types, the VS Code debug window often only showed a bunch of internal fields. The data was correct, but it wasn’t human-readable. The ridiculous part is that some tutorials I saw before stopped around launch.json. It wasn’t until recently, when I had an AI set up a new project for me, that it conveniently added preLaunchTask and gdb_printers.py, that I realized: debugging C++ in VS Code isn’t just about starting GDB. You can automatically trigger CMake compilation before debugging, and after hitting a breakpoint, you can even let GDB load a Python script to format business types into something readable for us. Honestly, this isn’t some black magic. But it perfectly filled two annoying gaps in daily C++ debugging: pre-launch build and variable display after a breakpoint.

Visual Studio Compilation Character Set [Converted]

C++ cross-platform development. Commonly encountered on Chinese operating systems: error C2001 - constant contains a newline character.

Visual Studio

cmake organizes the project compilation script, generating a temporary solution under the windows system for development. The reason for cross-platform compatibility is that the file encoding is chosen as utf-8.

The cited reference provides a detailed explanation of the causes of the problem from first principles.

Regarding encoding, MSVC has dedicated compilation options /source-charset and /execution-charset. The former indicates the encoding of the file itself, and the latter indicates what encoding the byte array inside the compiled character set is. Encoding issues can basically be solved using these two options.