[libcxx-commits] [libcxx] [libcxx]support freestanding libc++ (PR #208900)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 12 13:20:02 PDT 2026


================
@@ -60,11 +60,49 @@ size_t strlen(const char* s);
 #    pragma GCC system_header
 #  endif
 
+#  include <stddef.h>
 #  if __has_include_next(<string.h>)
 #    include_next <string.h>
-#  endif
+#  else
+#    ifndef __cplusplus
+extern "C" {
+#    endif
 
-#  include <stddef.h>
+/*
+We offer declarations for these C functions,
+leaving the implementations to be handled by users.
+*/
+
----------------
arhwx wrote:

I built it locally now, hosted GCC is fine, but freestanding fails as expected:
```
$ cat main.cpp 
#include <cstring>

int main() {
  return 0;
}

$ clang++ -fsyntax-only -ffreestanding -nostdinc++ -nostdlibinc -I build/freestanding/include/c++/v1/ main.cpp # compiles fine
$ g++ -fsyntax-only -nostdinc++ -I build/freestanding/include/c++/v1/ main.cpp # hosted, compiles fine
$ g++ -fsyntax-only -ffreestanding -nostdinc -I build/freestanding/include/c++/v1/ -I /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/include/ main.cpp
<cstring>:91:9: error: ‘strcoll’ has not been declared in ‘::’
<cstring>:92:9: error: ‘strxfrm’ has not been declared in ‘::’
<cstring>:102:9: error: ‘strerror’ has not been declared in ‘::’
```


https://github.com/llvm/llvm-project/pull/208900


More information about the libcxx-commits mailing list