NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
api.h
Go to the documentation of this file.
1
29#pragma once
30
31// The thread setting of this build, and the check that a translation unit agrees with it. Every public header
32// that includes Asio reaches api.h.
33#include <neograph/build_config.h>
34
35#if defined(NEOGRAPH_STATIC_BUILD)
36// Static-only build: no decoration, every symbol is a normal
37// member of the static archive.
38#define NEOGRAPH_API
39#elif defined(_WIN32) || defined(__CYGWIN__)
40#if defined(NEOGRAPH_BUILDING_LIBRARY)
41#define NEOGRAPH_API __declspec(dllexport)
42#else
43#define NEOGRAPH_API __declspec(dllimport)
44#endif
45#elif defined(__GNUC__) && __GNUC__ >= 4
46// Linux/macOS: explicit default visibility so a downstream
47// library built with -fvisibility=hidden still sees these.
48#define NEOGRAPH_API __attribute__((visibility("default")))
49#else
50#define NEOGRAPH_API
51#endif
52
53// Harness declarations belong to neograph_mcp_server but are also consumed by
54// the MCP client, A2A adapter, and SQLite store libraries.
55#if defined(NEOGRAPH_STATIC_BUILD)
56#define NEOGRAPH_MCP_SERVER_API
57#elif defined(_WIN32) || defined(__CYGWIN__)
58#if defined(NEOGRAPH_BUILDING_MCP_SERVER)
59#define NEOGRAPH_MCP_SERVER_API __declspec(dllexport)
60#else
61#define NEOGRAPH_MCP_SERVER_API __declspec(dllimport)
62#endif
63#elif defined(__GNUC__) && __GNUC__ >= 4
64#define NEOGRAPH_MCP_SERVER_API __attribute__((visibility("default")))
65#else
66#define NEOGRAPH_MCP_SERVER_API
67#endif
68
69// Harness declarations are owned by the top-level neograph_harness adapter.
70#if defined(NEOGRAPH_STATIC_BUILD)
71#define NEOGRAPH_HARNESS_API
72#elif defined(_WIN32) || defined(__CYGWIN__)
73#if defined(NEOGRAPH_BUILDING_HARNESS)
74#define NEOGRAPH_HARNESS_API __declspec(dllexport)
75#else
76#define NEOGRAPH_HARNESS_API __declspec(dllimport)
77#endif
78#elif defined(__GNUC__) && __GNUC__ >= 4
79#define NEOGRAPH_HARNESS_API __attribute__((visibility("default")))
80#else
81#define NEOGRAPH_HARNESS_API
82#endif
83
84// Program value declarations are owned by neograph_program. A distinct macro
85// prevents Windows consumers from importing them from neograph_core.
86#if defined(NEOGRAPH_STATIC_BUILD)
87#define NEOGRAPH_PROGRAM_API
88#elif defined(_WIN32) || defined(__CYGWIN__)
89#if defined(NEOGRAPH_BUILDING_PROGRAM)
90#define NEOGRAPH_PROGRAM_API __declspec(dllexport)
91#else
92#define NEOGRAPH_PROGRAM_API __declspec(dllimport)
93#endif
94#elif defined(__GNUC__) && __GNUC__ >= 4
95#define NEOGRAPH_PROGRAM_API __attribute__((visibility("default")))
96#else
97#define NEOGRAPH_PROGRAM_API
98#endif
99
100// PR 4 (v0.4.0): cross-compiler deprecation-warning suppression.
101// Used inside the engine where the legacy 8-virtual default chain
102// and add_cancel_hook fallback paths legitimately call deprecated
103// symbols on behalf of consumers who haven't migrated yet. User
104// code calling the same symbols still sees the warning.
105//
106// GCC / clang → -Wdeprecated-declarations
107// MSVC → C4996
108//
109// Block-style usage:
110// NEOGRAPH_PUSH_IGNORE_DEPRECATED
111// // ... legacy default chain body ...
112// NEOGRAPH_POP_IGNORE_DEPRECATED
113#if defined(__GNUC__) || defined(__clang__)
114#define NEOGRAPH_PUSH_IGNORE_DEPRECATED \
115 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
116#define NEOGRAPH_POP_IGNORE_DEPRECATED _Pragma("GCC diagnostic pop")
117#elif defined(_MSC_VER)
118#define NEOGRAPH_PUSH_IGNORE_DEPRECATED __pragma(warning(push)) __pragma(warning(disable : 4996))
119#define NEOGRAPH_POP_IGNORE_DEPRECATED __pragma(warning(pop))
120#else
121#define NEOGRAPH_PUSH_IGNORE_DEPRECATED
122#define NEOGRAPH_POP_IGNORE_DEPRECATED
123#endif
124
125// =========================================================================
126// Issue #16 — silent ODR-trap detection for cpp-httplib + OpenSSL.
127//
128// NeoGraph's bundled cpp-httplib is built with `CPPHTTPLIB_OPENSSL_SUPPORT`
129// defined (TLS ON). cpp-httplib's `ClientImpl` class adds extra members
130// when this macro is set, so a downstream TU that includes `<httplib.h>`
131// WITHOUT the macro sees a different class layout — a One Definition Rule
132// violation. The linker keeps a single inline-function instantiation
133// arbitrarily, so callers compiled against the wrong layout read members
134// at the wrong offsets and SEGV inside the resolver
135// (`getaddrinfo` / `internal_strlen`) the first time the LLM endpoint
136// is hit.
137//
138// This guard catches the ordering case where the user's TU includes
139// `<httplib.h>` BEFORE the first NeoGraph header (the natural order in
140// many builds — system headers first, project headers second). The
141// cpp-httplib include guard `CPPHTTPLIB_HTTPLIB_H` is already defined
142// at this point, and we can compare macro state.
143//
144// Caveat: this guard does NOT fire when the user includes any NeoGraph
145// header BEFORE `<httplib.h>` — at that point cpp-httplib hasn't been
146// processed yet, its include guard isn't visible, so we have nothing to
147// check against. For that ordering, the docstring on
148// `include/neograph/llm/schema_provider.h` and
149// `docs/troubleshooting.md` "C++ consumers — httplib.h macro
150// consistency" explain the symptom and the fix.
151//
152// Disable the guard with `-DNEOGRAPH_SKIP_HTTPLIB_MACRO_GUARD=1` in
153// build flags — last-resort escape for downstream TUs that have a
154// genuine reason to mismatch (vanishingly rare; the canonical fix is
155// to define the macro consistently).
156#if defined(CPPHTTPLIB_HTTPLIB_H) && !defined(CPPHTTPLIB_OPENSSL_SUPPORT) && \
157 !defined(NEOGRAPH_SKIP_HTTPLIB_MACRO_GUARD)
158#error \
159 "NeoGraph: <httplib.h> was included before this NeoGraph header without CPPHTTPLIB_OPENSSL_SUPPORT defined. NeoGraph's bundled cpp-httplib is built with TLS support ON; a mismatched macro state between TUs is an ODR violation that silently SEGVs inside getaddrinfo at runtime (issue #16). Fix: `#define CPPHTTPLIB_OPENSSL_SUPPORT` BEFORE `#include <httplib.h>` in this TU, OR add `target_compile_definitions(<your_target> PRIVATE CPPHTTPLIB_OPENSSL_SUPPORT)` to your CMakeLists. See docs/troubleshooting.md \"C++ consumers — httplib.h macro consistency\". Last-resort opt-out: `-DNEOGRAPH_SKIP_HTTPLIB_MACRO_GUARD=1`."
160#endif