Skip to content

Missing definitions when using zig drop-in c/c++ compiler and clangd #25979

Description

@hly1204

Zig Version

0.15.2

Steps to Reproduce and Observed Behavior

Install Msys2 and install zig by

pacman -S mingw-w64-clang-x86_64-zig \
          mingw-w64-clang-x86_64-cmake \
          mingw-w64-clang-x86_64-ninja

Install VSCode and clangd extension in the marketplace.

Clone mrexodia/zig-cross to a workspace folder, in my case <workspace>/3rdparty.

Modify the *.cmd files in zig-cross/cmake by changing zig to <full-path-to-zig>, in my case C:\msys64\clang64\bin\zig.exe.

Set VSCode settings for a workspace with

{
    "clangd.path": "C:/msys64/clang64/bin/clangd.exe",
    "clangd.arguments": [
        "--query-driver=D:/Repos/zig_test/3rdparty/zig-cross/cmake/zig-cc.cmd,D:/Repos/zig_test/3rdparty/zig-cross/cmake/zig-c++.cmd",
        "--log=verbose",
        "--pretty",
        "--compile-commands-dir=${workspaceFolder}",
        "--header-insertion=never",
        "--all-scopes-completion",
        "--clang-tidy",
        "--pch-storage=memory",
        "-j=4"
    ]
}

Create a C++ source file main.cc

#include <iostream>

int main() {
  std::cout << "Hello, world" << std::endl;
  return 0;
}

Create CMakeLists.txt

cmake_minimum_required(VERSION 3.21)
project(text LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(test main.cc)

Run several commands in Msys2/UCRT64 shell

mkdir build && cd build && cmake -D CMAKE_TOOLCHAIN_FILE=3rdparty/zig-cross/x86_64-windows-gnu.cmake ..
cp -pv compile_commands.json ..

Now restart the clangd language server.

Image

The language server doesnot work properly because of missing definitions for libc++.

After some digging, I found that there should be a __config_site.h in libc++, but it seems that zig will use -D when compiling. Clangd failed to detect these definitions, so it cannot work unless we use the verbose mode to compile and add these definitions manually in CMakeLists.txt to generate a database file which contains these definitions.

Image

Expected Behavior

When using clang in Msys2/UCRT64, clangd works fine.

Image

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Nov 19, 2025
  2. changed the title [-]Missing definitions when using clangd[/-] [+]Missing definitions when using zig drop-in c/c++ compiler and clangd[/+] on Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions