| Message ID | 20251024184009.740860-1-raj.khem@gmail.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Hi This addresses a long-standing issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/226 2025. 10. 24. 20:40 keltezéssel, Khem Raj írta: > Clang on linux can be defaulting to use libstdc++, it > should be using default platform C++ runtime library which the > toolchain should be configured to do the right thing > > Add logic in meson file to detect C++ runtime used by toolchain > and defile -stdlib= parameter accordingly > > Signed-off-by: Khem Raj <raj.khem@gmail.com> > --- > meson.build | 32 +++++++++++++++++++++----------- > 1 file changed, 21 insertions(+), 11 deletions(-) > > diff --git a/meson.build b/meson.build > index fd508fd7..5707f850 100644 > --- a/meson.build > +++ b/meson.build > @@ -118,7 +118,24 @@ cpp_arguments = [ > '-Wnon-virtual-dtor', > ] > > -cxx_stdlib = 'libstdc++' > +# Try to detect libc++ > +libcxx_ver = cxx.get_define('_LIBCPP_VERSION', > + prefix: '#include <vector>\n') > + > +# Try to detect libstdc++ > +glibcxx_ver = cxx.get_define('__GLIBCXX__', > + prefix: '#include <vector>\n') meson uses the ciso646 header, so I would think we should use that as well. > + > +stdlib_msg = 'unknown' > + > +if libcxx_ver != '' I would just use `cpp.has_header_symbol('ciso646', '_LIBCPP_VERSION')` since you're only really interested in the existence. > + cxx_stdlib = 'libc++' > +elif glibcxx_ver != '' Similar thing here. > + # __GLIBCXX__ is usually a yyyymmdd date code > + cxx_stdlib = 'libstdc++' > +endif > + > +message('Detected C++ standard library: ' + cxx_stdlib) > > if cc.get_id() == 'clang' > if cc.version().version_compare('<9') > @@ -138,16 +155,9 @@ if cc.get_id() == 'clang' > ] > endif > endif > - > - # Use libc++ by default if available instead of libstdc++ when compiling > - # with clang. > - if cc.find_library('c++', required : false).found() > - cpp_arguments += [ > - '-stdlib=libc++', > - ] > - cxx_stdlib = 'libc++' > - endif > - > + cpp_arguments += [ > + '-stdlib=' + cxx_stdlib, > + ] I think this can be dropped, no? Regards, Barnabás Pőcze > cpp_arguments += [ > '-Wextra-semi', > '-Wthread-safety',
diff --git a/meson.build b/meson.build index fd508fd7..5707f850 100644 --- a/meson.build +++ b/meson.build @@ -118,7 +118,24 @@ cpp_arguments = [ '-Wnon-virtual-dtor', ] -cxx_stdlib = 'libstdc++' +# Try to detect libc++ +libcxx_ver = cxx.get_define('_LIBCPP_VERSION', + prefix: '#include <vector>\n') + +# Try to detect libstdc++ +glibcxx_ver = cxx.get_define('__GLIBCXX__', + prefix: '#include <vector>\n') + +stdlib_msg = 'unknown' + +if libcxx_ver != '' + cxx_stdlib = 'libc++' +elif glibcxx_ver != '' + # __GLIBCXX__ is usually a yyyymmdd date code + cxx_stdlib = 'libstdc++' +endif + +message('Detected C++ standard library: ' + cxx_stdlib) if cc.get_id() == 'clang' if cc.version().version_compare('<9') @@ -138,16 +155,9 @@ if cc.get_id() == 'clang' ] endif endif - - # Use libc++ by default if available instead of libstdc++ when compiling - # with clang. - if cc.find_library('c++', required : false).found() - cpp_arguments += [ - '-stdlib=libc++', - ] - cxx_stdlib = 'libc++' - endif - + cpp_arguments += [ + '-stdlib=' + cxx_stdlib, + ] cpp_arguments += [ '-Wextra-semi', '-Wthread-safety',
Clang on linux can be defaulting to use libstdc++, it should be using default platform C++ runtime library which the toolchain should be configured to do the right thing Add logic in meson file to detect C++ runtime used by toolchain and defile -stdlib= parameter accordingly Signed-off-by: Khem Raj <raj.khem@gmail.com> --- meson.build | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)