diff --git a/.gitignore b/.gitignore index d2a8df0e9..53d6151e7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ OneLocBuild # ignore imported localization xlf directory vscode-translations-import + +# Ignore Fib sample build artifacts +Code Samples/Fib/fib.out +Code Samples/Fib/fib.out.dSYM/ diff --git a/Code Samples/Fib/.vscode/launch.json b/Code Samples/Fib/.vscode/launch.json index 301f8c5f2..b1349d1a4 100644 --- a/Code Samples/Fib/.vscode/launch.json +++ b/Code Samples/Fib/.vscode/launch.json @@ -3,7 +3,6 @@ "configurations": [ { "name": "(gdb) Launch", - "preLaunchTask": "build", "type": "cppdbg", "request": "launch", "args": [], diff --git a/Code Samples/Fib/.vscode/tasks.json b/Code Samples/Fib/.vscode/tasks.json index 104a10aad..49c3004f1 100644 --- a/Code Samples/Fib/.vscode/tasks.json +++ b/Code Samples/Fib/.vscode/tasks.json @@ -1,50 +1,34 @@ +{ + "version": "2.0.0", + "tasks": [] +} +```jsonc +{ + "version": "2.0.0", + "tasks": [] +} +``` +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + // The explicit "build" task was removed because the sample now uses a direct g++ command + // (the Makefile was removed). If you prefer a build task, add one that runs the + // appropriate g++ command for your platform or call `build.cmd` on Windows. + "tasks": [] +} { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", - "tasks": [ - { - "label": "build", - "type": "shell", - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { + { + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + // The explicit "build" task was removed because the sample now uses a direct g++ command + // (the Makefile was removed). If you prefer a build task, add one that runs the + // appropriate g++ command for your platform or call `build.cmd` on Windows. + "tasks": [] + } "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared" - }, - "windows": { - "command": "${workspaceRoot}/build.cmd", - "args": [ - "", // Path to the bin folder containing g++ to compile - "fib.exe" // Output executable name - ] - }, - "linux": { - "command": "g++", - "args": [ - "-g", - "*.cpp", - "-lpthread", - "--std=c++11", - "-o", - "fib.out" - ] - }, - "osx": { - "command": "g++", - "args": [ - "-g", - "*.cpp", - "-lpthread", - "--std=c++11", - "-o", - "fib.out" - ] - } - } - ] } diff --git a/Code Samples/Fib/README.md b/Code Samples/Fib/README.md index 6402c911b..a9f9eb045 100644 --- a/Code Samples/Fib/README.md +++ b/Code Samples/Fib/README.md @@ -1,3 +1,51 @@ # Fib +This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. + +## Building + +Use one of the commands below to build the sample. The Makefile was removed and the sample is built with g++ directly. + +```bash +# Linux / macOS +g++ -g *.cpp -std=c++11 -o fib.out + +# Windows (MinGW) +g++ -g *.cpp -std=c++11 -o fib.exe +``` + +On Windows you can also run the included `build.cmd` if you prefer (it expects the path to a MinGW/Cygwin `bin` folder and an output name): + +```powershell +.\build.cmd fib.exe +``` + +After building, use the `launch.json` in this folder (or your own) to debug the produced binary. +```markdown +# Fib + +This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. + +## Building + +Use one of the commands below to build the sample. The Makefile was removed and the sample is built with g++ directly. + +```bash +# Linux / macOS +g++ -g *.cpp -std=c++11 -o fib.out + +# Windows (MinGW) +g++ -g *.cpp -std=c++11 -o fib.exe +``` + +On Windows you can also run the included `build.cmd` if you prefer (it expects the path to a MinGW/Cygwin `bin` folder and an output name): + +```powershell +.\build.cmd fib.exe +``` + +After building, use the `launch.json` in this folder (or your own) to debug the produced binary. +``` +# Fib + This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. \ No newline at end of file diff --git a/Code Samples/Fib/build.cmd b/Code Samples/Fib/build.cmd index 821c62747..05879b7cf 100644 --- a/Code Samples/Fib/build.cmd +++ b/Code Samples/Fib/build.cmd @@ -1,2 +1,3 @@ -SET PATH=%PATH%;%1 -g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 \ No newline at end of file +@echo off +SET PATH=%PATH%;%1 +g++ -g *.cpp --std=c++11 -O0 -o %2 diff --git a/Code Samples/Fib/thread.cpp b/Code Samples/Fib/thread.cpp index bef34e9c7..1e5bd00cb 100644 --- a/Code Samples/Fib/thread.cpp +++ b/Code Samples/Fib/thread.cpp @@ -24,7 +24,7 @@ void * thread_proc(void* ctx) int tid = g_tid++; char thread_name[16]; - sprintf(thread_name, "Thread %d", tid); + snprintf(thread_name, sizeof(thread_name), "Thread %d", tid); #ifdef __APPLE__ pthread_setname_np(thread_name); #else @@ -45,4 +45,5 @@ void * thread_proc(void* ctx) } std::cout << thread_name << " exited!" << std::endl; + return nullptr; } \ No newline at end of file