mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.57k stars 1.62k forks source link

Would be nice for documentation to show an easy way to use libc++ from system packages as cpp_stdlib #12625

Open sammyj85 opened 10 months ago

sammyj85 commented 10 months ago

I am running Fedora Linux, and I'm interested in using libc++ as the stdlib with Clang. I have installed the system package for libc++ (not built it myself).

I see there's other issue bugs about automatically selecting libc++ when there is no libstdc++ provided by default (such as FreeBSD). But I would like to manually choose libc++ over the default libstdc++.

I cannot find an example of how to do this. The documentation seems to infer the native/cross file should have:

[properties]
cpp_stdlib = 'libc++'
# or
cpp_stdlib = ['c++', 'cxx_dep']

https://mesonbuild.com/Cross-compilation.html#using-a-custom-standard-library

Where cxx_dep is to be defined elsewhere, such as cxx_dep = dependency('c++') in the main meson.build (which duplicates the library name to search for).

When trying do meson setup with the native file for clang/lld/libc++, it gives the error:

C compiler for the host machine: clang (clang 16.0.6 "clang version 16.0.6 (Fedora 16.0.6-3.fc38)")
C linker for the host machine: clang ld.lld 16.0.6
C++ compiler for the host machine: clang++ (clang 16.0.6 "clang version 16.0.6 (Fedora 16.0.6-3.fc38)")
C++ linker for the host machine: clang++ ld.lld 16.0.6
Looking for a fallback subproject for the dependency cpp_stdlib because:
Use of fallback dependencies is forced.

meson.build:9:0: ERROR: Neither a subproject directory nor a c++.wrap file was found.

The meson.build dependency('c++') command didn't find the built in system package of libc++.

So perhaps it's popular enough that there's a wrap for it? I searched the WrapDB, and there was no libc++/c++/libcxx.

https://mesonbuild.com/Wrapdb-projects.html

How do I achieve this? Could the documentation be expanded to include this libc++ example when it documents [lang]_stdlib (first link above)? Surely this is a more popular standard library option than the near zero level of documentation I can find suggests it is.

QuLogic commented 10 months ago

I think for clang++, you'd want to pass -stdlib=c++, as in https://libcxx.llvm.org/UsingLibcxx.html#using-libc-when-it-is-not-the-system-default

sammyj85 commented 10 months ago

Isn't that the job of Meson to add that flag when I use cpp_stdlib = 'c++'?

What is the purpose of Meson's cpp_stdlib if not?

stephanlachnit commented 4 months ago

Isn't that the job of Meson to add that flag when I use cpp_stdlib = 'c++'?

It is, but it doesn't work. I needed to set CXXFLAGS="-stdlib=libc++".

sammyj85 commented 4 months ago

Isn't that the job of Meson to add that flag when I use cpp_stdlib = 'c++'?

It is, but it doesn't work. I needed to set CXXFLAGS="-stdlib=libc++".

That is the whole point of this issue - cpp_stdlib exists but doesn't work (at least according to how the documentation suggests it should).

The options are:

eli-schwartz commented 4 months ago

The documentation is pretty straightforward that this variable is not expected to contain the name of a -stdlib= value, but rather that it should contain the name of a subproject dependency which builds a (most likely embedded) stdlib.

Meson would then also compile with -nostdlib++ to avoid linking in multiple stdlibs.

sammyj85 commented 4 months ago

Thanks for the reply, and that's a relief that it's pretty straightforward.

So to answer the original question, how would an example of using the system-provided libc++ look?