Skip to content

LocalLLMClientLlama: 'memory' file not found — C wrapper needs C++ stdlib #94

@gsdali

Description

@gsdali

Summary

LocalLLMClientLlama fails to build because its C wrapper target
(LocalLLMClientLlamaC) doesn't have C++ stdlib available — #include <memory> fails with "file not found". The wrapper is a C/Objective-C target
that includes C++ headers from llama.cpp (utils.h, chat.h) but isn't
configured to compile with the C++ stdlib.

Repro

Consume LocalLLMClient main + LocalLLMClientLlama from a Swift 6 package:

.package(url: "https://github.com/tattn/LocalLLMClient.git", revision: "<main HEAD>"),

.target(
    name: "MyTarget",
    dependencies: [
        .product(name: "LocalLLMClient", package: "LocalLLMClient"),
        .product(name: "LocalLLMClientLlama", package: "LocalLLMClient"),
    ],
    swiftSettings: [
        .interoperabilityMode(.Cxx),  // tried — doesn't help, since the
                                      // failure is in upstream's C target
    ]
),

swift build

.build/checkouts/LocalLLMClient/Sources/LocalLLMClientLlamaC/include/utils.h:1:10:
error: 'memory' file not found
 1 | #include <memory>
   |          `- error: 'memory' file not found
 2 | #include "../common/chat.h"

<unknown>:0: error: could not build Objective-C module 'LocalLLMClientLlamaC'

The chain: LocalLLMClientLlamaC.hmtmd.hutils.h<memory>
not found because the target is built as Objective-C / C, not C++.

Likely fix

The LocalLLMClientLlamaC target in Package.swift needs cxxSettings (or
needs to be declared as a .target with publicHeadersPath configured for
C++ + a .headerSearchPath that picks up llama.cpp's common/ directory).
Something like:

.target(
    name: "LocalLLMClientLlamaC",
    dependencies: [/* llama-binary, etc. */],
    publicHeadersPath: "include",
    cSettings: [
        .headerSearchPath("../common"),
    ],
    cxxSettings: [
        .headerSearchPath("../common"),
        .define("..."),
    ],
    linkerSettings: [/* ... */]
)

Plus making the target file-extensions C++ if any of its own .m / .c files
are actually C++ in disguise.

The clean separation would be: a pure-C LocalLLMClientLlamaC target that
forwards to a separate C++ LocalLLMClientLlamaCxx target. But a cxxSettings
on the existing target is the minimum-disruption fix.

Context

Filed while wiring LocalLLMClient into OCCTSwiftPartsAgent. Pairs with
the MLX-backend Tokenizers issue (filed separately) — together they leave
LocalLLMClient unable to deliver any local-inference backend on current main.

For OCCTSwiftPartsAgent we've deferred the LocalLLMClient integration
pending a fix on either backend; the project meanwhile drives local
inference through OpenAI-compat (LM Studio) for Mac dev. The local
in-process path is needed for the iPad target, which can't run LM Studio.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions