2.5 KiB
2.5 KiB
Perfect! Let’s extend the README.md with a “Quick Commands” section so that you have a ready reference for all the main tasks. I’ll integrate it cleanly at the end of the existing README.
7. Quick Commands
These commands are handy for building, formatting, analyzing, and running tutorials.
Build Project
# Configure and generate build system
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Build all tutorials
cmake --build build
# Build a specific tutorial (e.g., tut1)
cmake --build build --target tut1
Run Executables
# Run tut1 manually
./build/tut1/tut1 arg1 arg2
# Run tut2 manually
./build/tut2/tut2
Or use VS Code debug/run panel (CMake Tools can auto-generate temporary launch configs).
Format Code
# Format a single file
clang-format -i tut1/main.cpp
# Format all cpp/h files in the project
find . -name "*.cpp" -o -name "*.h" | xargs clang-format -i
Static Analysis with clang-tidy
# Analyze a single file
clang-tidy tut1/main.cpp -p build -header-filter='^/home/ys/family-repo/code/cplusplus/learning/.*' -quiet
# Example: test warning by introducing a short variable name
# double x; // triggers readability-identifier-length
Debugging in VS Code
-
Use CMake Tools panel → Debug target
- Automatically sets up GDB for the executable
- Supports breakpoints, stepping, and inspecting variables
-
Optional: Create
.vscode/launch.jsonfor:- Custom arguments
- Environment variables
- Stop-at-entry behavior
"args": ["arg1", "arg2"],
"stopAtEntry": false,
"environment": [{"name": "MY_FLAG", "value": "1"}]
Shared Libraries
# Build shared library and tutorials
cmake --build build
# Ensure runtime can find .so files
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/family-repo/code/cplusplus/learning/build/libcommon
- Tutorials link against
libcommonor other shared libraries. - Step into shared library code in VS Code debugger.
Notes
- Always run
cmake -B buildif you add new tutorials or change CMake files. - Run
clang-formatregularly to maintain consistent code style. - Run
clang-tidyto catch bugs or style issues early. - Debugging works even without
launch.jsondue to CMake Tools auto-config.
✅ With this section, your **README.md** now becomes a **single-page guide** for building, formatting, analyzing, debugging, and managing multiple tutorials with shared libraries.
It will serve as a **perfect context** for continuing the session later.