NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
api.h
Go to the documentation of this file.
1
33#pragma once
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// PR 4 (v0.4.0): cross-compiler deprecation-warning suppression.
54// Used inside the engine where the legacy 8-virtual default chain
55// and add_cancel_hook fallback paths legitimately call deprecated
56// symbols on behalf of consumers who haven't migrated yet. User
57// code calling the same symbols still sees the warning.
58//
59// GCC / clang → -Wdeprecated-declarations
60// MSVC → C4996
61//
62// Block-style usage:
63// NEOGRAPH_PUSH_IGNORE_DEPRECATED
64// // ... legacy default chain body ...
65// NEOGRAPH_POP_IGNORE_DEPRECATED
66#if defined(__GNUC__) || defined(__clang__)
67 #define NEOGRAPH_PUSH_IGNORE_DEPRECATED \
68 _Pragma("GCC diagnostic push") \
69 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
70 #define NEOGRAPH_POP_IGNORE_DEPRECATED \
71 _Pragma("GCC diagnostic pop")
72#elif defined(_MSC_VER)
73 #define NEOGRAPH_PUSH_IGNORE_DEPRECATED \
74 __pragma(warning(push)) \
75 __pragma(warning(disable : 4996))
76 #define NEOGRAPH_POP_IGNORE_DEPRECATED \
77 __pragma(warning(pop))
78#else
79 #define NEOGRAPH_PUSH_IGNORE_DEPRECATED
80 #define NEOGRAPH_POP_IGNORE_DEPRECATED
81#endif
82
83// =========================================================================
84// Issue #16 — silent ODR-trap detection for cpp-httplib + OpenSSL.
85//
86// NeoGraph's bundled cpp-httplib is built with `CPPHTTPLIB_OPENSSL_SUPPORT`
87// defined (TLS ON). cpp-httplib's `ClientImpl` class adds extra members
88// when this macro is set, so a downstream TU that includes `<httplib.h>`
89// WITHOUT the macro sees a different class layout — a One Definition Rule
90// violation. The linker keeps a single inline-function instantiation
91// arbitrarily, so callers compiled against the wrong layout read members
92// at the wrong offsets and SEGV inside the resolver
93// (`getaddrinfo` / `internal_strlen`) the first time the LLM endpoint
94// is hit.
95//
96// This guard catches the ordering case where the user's TU includes
97// `<httplib.h>` BEFORE the first NeoGraph header (the natural order in
98// many builds — system headers first, project headers second). The
99// cpp-httplib include guard `CPPHTTPLIB_HTTPLIB_H` is already defined
100// at this point, and we can compare macro state.
101//
102// Caveat: this guard does NOT fire when the user includes any NeoGraph
103// header BEFORE `<httplib.h>` — at that point cpp-httplib hasn't been
104// processed yet, its include guard isn't visible, so we have nothing to
105// check against. For that ordering, the docstring on
106// `include/neograph/llm/schema_provider.h` and
107// `docs/troubleshooting.md` "C++ consumers — httplib.h macro
108// consistency" explain the symptom and the fix.
109//
110// Disable the guard with `-DNEOGRAPH_SKIP_HTTPLIB_MACRO_GUARD=1` in
111// build flags — last-resort escape for downstream TUs that have a
112// genuine reason to mismatch (vanishingly rare; the canonical fix is
113// to define the macro consistently).
114#if defined(CPPHTTPLIB_HTTPLIB_H) \
115 && !defined(CPPHTTPLIB_OPENSSL_SUPPORT) \
116 && !defined(NEOGRAPH_SKIP_HTTPLIB_MACRO_GUARD)
117# error "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`."
118#endif