From 1602cdb01dcb15d6053b8c5be0b5d9810be53c70 Mon Sep 17 00:00:00 2001 From: geoyee Date: Sun, 31 May 2026 19:28:04 +0800 Subject: [PATCH 1/3] fix: Fixed the issue of examples failing to compile under MSVC --- examples/context-engineering/context-engineering.cpp | 6 ++++++ examples/memory/memory.cpp | 6 ++++++ examples/multi-agent/multi-agent.cpp | 6 ++++++ examples/shared/chat_loop.h | 12 +++++++++++- examples/shared/logging_callback.h | 10 ++++++++++ examples/shell/shell.cpp | 9 +++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/examples/context-engineering/context-engineering.cpp b/examples/context-engineering/context-engineering.cpp index 0390d32..7f00d26 100644 --- a/examples/context-engineering/context-engineering.cpp +++ b/examples/context-engineering/context-engineering.cpp @@ -15,7 +15,13 @@ #include #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 static constexpr size_t DEFAULT_MAX_TOOL_CALLS = 1; diff --git a/examples/memory/memory.cpp b/examples/memory/memory.cpp index 7e14aa9..9316357 100644 --- a/examples/memory/memory.cpp +++ b/examples/memory/memory.cpp @@ -15,7 +15,13 @@ #include #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 using agent_cpp::json; diff --git a/examples/multi-agent/multi-agent.cpp b/examples/multi-agent/multi-agent.cpp index f4e5d44..ea84b0a 100644 --- a/examples/multi-agent/multi-agent.cpp +++ b/examples/multi-agent/multi-agent.cpp @@ -15,7 +15,13 @@ #include #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 using agent_cpp::json; diff --git a/examples/shared/chat_loop.h b/examples/shared/chat_loop.h index 3d090cc..ae0204c 100644 --- a/examples/shared/chat_loop.h +++ b/examples/shared/chat_loop.h @@ -5,9 +5,15 @@ #include #include #include -#include #include +#if _WIN32 +#include +#define isatty _isatty +#else +#include +#endif // _WIN32 + // Run an interactive chat loop with the given agent. // Reads user input from stdin and prints agent responses to stdout. // The loop continues until the user enters an empty line. @@ -48,3 +54,7 @@ run_chat_loop(agent_cpp::Agent& agent) printf("\nšŸ‘‹ Goodbye!\n"); } + +#if _WIN32 +#undef isatty +#endif // _WIN32 diff --git a/examples/shared/logging_callback.h b/examples/shared/logging_callback.h index 72770a1..82d65aa 100644 --- a/examples/shared/logging_callback.h +++ b/examples/shared/logging_callback.h @@ -4,7 +4,13 @@ #include "tool_result.h" #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 // Logging callback to display tool execution information. // Shared across examples to provide consistent tool call logging. @@ -47,3 +53,7 @@ class LoggingCallback : public agent_cpp::Callback } } }; + +#if _WIN32 +#undef isatty +#endif // _WIN32 diff --git a/examples/shell/shell.cpp b/examples/shell/shell.cpp index d66d06b..ed1522b 100644 --- a/examples/shell/shell.cpp +++ b/examples/shell/shell.cpp @@ -15,7 +15,16 @@ #include #include #include + +#if _WIN32 +#include +#include +#define isatty _isatty +#define popen _popen +#define pclose _pclose +#else #include +#endif // _WIN32 using agent_cpp::json; using agent_cpp::ToolExecutionSkipped; From d5c413cf2bdf215aa5835f38ad52881ad6abc6bb Mon Sep 17 00:00:00 2001 From: geoyee Date: Sun, 31 May 2026 21:57:01 +0800 Subject: [PATCH 2/3] fix: Remove non-required items --- examples/context-engineering/context-engineering.cpp | 2 +- examples/memory/memory.cpp | 7 ------- examples/multi-agent/multi-agent.cpp | 7 ------- examples/shared/chat_loop.h | 4 ++-- examples/shared/logging_callback.h | 4 ++-- examples/shell/shell.cpp | 2 +- 6 files changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/context-engineering/context-engineering.cpp b/examples/context-engineering/context-engineering.cpp index 7f00d26..fd148eb 100644 --- a/examples/context-engineering/context-engineering.cpp +++ b/examples/context-engineering/context-engineering.cpp @@ -16,7 +16,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #define isatty _isatty #else diff --git a/examples/memory/memory.cpp b/examples/memory/memory.cpp index 9316357..3fe4f0c 100644 --- a/examples/memory/memory.cpp +++ b/examples/memory/memory.cpp @@ -16,13 +16,6 @@ #include #include -#if _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - using agent_cpp::json; class MemoryStore diff --git a/examples/multi-agent/multi-agent.cpp b/examples/multi-agent/multi-agent.cpp index ea84b0a..6d10b97 100644 --- a/examples/multi-agent/multi-agent.cpp +++ b/examples/multi-agent/multi-agent.cpp @@ -16,13 +16,6 @@ #include #include -#if _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - using agent_cpp::json; class MathAgent; diff --git a/examples/shared/chat_loop.h b/examples/shared/chat_loop.h index ae0204c..fda4c7b 100644 --- a/examples/shared/chat_loop.h +++ b/examples/shared/chat_loop.h @@ -7,7 +7,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #define isatty _isatty #else @@ -55,6 +55,6 @@ run_chat_loop(agent_cpp::Agent& agent) printf("\nšŸ‘‹ Goodbye!\n"); } -#if _WIN32 +#ifdef _WIN32 #undef isatty #endif // _WIN32 diff --git a/examples/shared/logging_callback.h b/examples/shared/logging_callback.h index 82d65aa..e18e270 100644 --- a/examples/shared/logging_callback.h +++ b/examples/shared/logging_callback.h @@ -5,7 +5,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #define isatty _isatty #else @@ -54,6 +54,6 @@ class LoggingCallback : public agent_cpp::Callback } }; -#if _WIN32 +#ifdef _WIN32 #undef isatty #endif // _WIN32 diff --git a/examples/shell/shell.cpp b/examples/shell/shell.cpp index ed1522b..e339bf7 100644 --- a/examples/shell/shell.cpp +++ b/examples/shell/shell.cpp @@ -16,7 +16,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #include #define isatty _isatty From 2aad6174e27c9cfbe24c4e32dccb9e249b56908a Mon Sep 17 00:00:00 2001 From: daavoo Date: Tue, 25 Aug 2026 16:57:05 +0200 Subject: [PATCH 3/3] fix: Consolidate the MSVC compatibility shim for examples Move the isatty/popen/pclose shim into a single examples/shared/platform_compat.h instead of repeating the same #ifdef _WIN32 block in four places. - Drop the trailing `#undef isatty` from the shared headers. It made including them depend on order, and an identical macro redefinition is legal, so it was never needed. - Remove the stale include from the tracing example, which never used isatty. Co-Authored-By: Claude Opus 5 (1M context) --- .../context-engineering/context-engineering.cpp | 8 +------- examples/shared/chat_loop.h | 12 +----------- examples/shared/logging_callback.h | 12 +----------- examples/shared/platform_compat.h | 16 ++++++++++++++++ examples/shell/shell.cpp | 11 +---------- examples/tracing/tracing.cpp | 1 - 6 files changed, 20 insertions(+), 40 deletions(-) create mode 100644 examples/shared/platform_compat.h diff --git a/examples/context-engineering/context-engineering.cpp b/examples/context-engineering/context-engineering.cpp index fd148eb..9bd6447 100644 --- a/examples/context-engineering/context-engineering.cpp +++ b/examples/context-engineering/context-engineering.cpp @@ -8,6 +8,7 @@ #include "llama.h" #include "logging_callback.h" #include "model.h" +#include "platform_compat.h" #include "tool.h" #include #include @@ -16,13 +17,6 @@ #include #include -#ifdef _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - static constexpr size_t DEFAULT_MAX_TOOL_CALLS = 1; // Callback that trims old tool calls from the context diff --git a/examples/shared/chat_loop.h b/examples/shared/chat_loop.h index fda4c7b..5f08d6d 100644 --- a/examples/shared/chat_loop.h +++ b/examples/shared/chat_loop.h @@ -2,18 +2,12 @@ #include "agent.h" #include "chat.h" +#include "platform_compat.h" #include #include #include #include -#ifdef _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - // Run an interactive chat loop with the given agent. // Reads user input from stdin and prints agent responses to stdout. // The loop continues until the user enters an empty line. @@ -54,7 +48,3 @@ run_chat_loop(agent_cpp::Agent& agent) printf("\nšŸ‘‹ Goodbye!\n"); } - -#ifdef _WIN32 -#undef isatty -#endif // _WIN32 diff --git a/examples/shared/logging_callback.h b/examples/shared/logging_callback.h index e18e270..eeb79bb 100644 --- a/examples/shared/logging_callback.h +++ b/examples/shared/logging_callback.h @@ -1,17 +1,11 @@ #pragma once #include "callbacks.h" +#include "platform_compat.h" #include "tool_result.h" #include #include -#ifdef _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - // Logging callback to display tool execution information. // Shared across examples to provide consistent tool call logging. class LoggingCallback : public agent_cpp::Callback @@ -53,7 +47,3 @@ class LoggingCallback : public agent_cpp::Callback } } }; - -#ifdef _WIN32 -#undef isatty -#endif // _WIN32 diff --git a/examples/shared/platform_compat.h b/examples/shared/platform_compat.h new file mode 100644 index 0000000..5aadf7a --- /dev/null +++ b/examples/shared/platform_compat.h @@ -0,0 +1,16 @@ +#pragma once + +// Small compatibility shim so the examples build with MSVC, which does not +// ship and prefixes the POSIX names with an underscore. +// Shared across examples to avoid repeating the same #ifdef block. + +#ifdef _WIN32 +#include + +#define isatty _isatty +#define popen _popen +#define pclose _pclose + +#else +#include +#endif // _WIN32 diff --git a/examples/shell/shell.cpp b/examples/shell/shell.cpp index e339bf7..8a7982b 100644 --- a/examples/shell/shell.cpp +++ b/examples/shell/shell.cpp @@ -6,6 +6,7 @@ #include "error_recovery_callback.h" #include "llama.h" #include "model.h" +#include "platform_compat.h" #include "tool.h" #include @@ -16,16 +17,6 @@ #include #include -#ifdef _WIN32 -#include -#include -#define isatty _isatty -#define popen _popen -#define pclose _pclose -#else -#include -#endif // _WIN32 - using agent_cpp::json; using agent_cpp::ToolExecutionSkipped; diff --git a/examples/tracing/tracing.cpp b/examples/tracing/tracing.cpp index 9e79dd7..839d4d8 100644 --- a/examples/tracing/tracing.cpp +++ b/examples/tracing/tracing.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include namespace trace_api = opentelemetry::trace;