[{"id":36474,"web_url":"https://patchwork.libcamera.org/comment/36474/","msgid":"<b9f05c72-666a-4cb1-a39c-7112fe355049@ideasonboard.com>","date":"2025-10-27T08:28:02","subject":"Re: [PATCH] libcamera: Do not assume libc++ with clang","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n\nThis addresses a long-standing issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/226\n\n2025. 10. 24. 20:40 keltezéssel, Khem Raj írta:\n> Clang on linux can be defaulting to use libstdc++, it\n> should be using default platform C++ runtime library which the\n> toolchain should be configured to do the right thing\n> \n> Add logic in meson file to detect C++ runtime used by toolchain\n> and defile -stdlib= parameter accordingly\n> \n> Signed-off-by: Khem Raj <raj.khem@gmail.com>\n> ---\n>   meson.build | 32 +++++++++++++++++++++-----------\n>   1 file changed, 21 insertions(+), 11 deletions(-)\n> \n> diff --git a/meson.build b/meson.build\n> index fd508fd7..5707f850 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -118,7 +118,24 @@ cpp_arguments = [\n>       '-Wnon-virtual-dtor',\n>   ]\n> \n> -cxx_stdlib = 'libstdc++'\n> +# Try to detect libc++\n> +libcxx_ver = cxx.get_define('_LIBCPP_VERSION',\n> +  prefix: '#include <vector>\\n')\n> +\n> +# Try to detect libstdc++\n> +glibcxx_ver = cxx.get_define('__GLIBCXX__',\n> +  prefix: '#include <vector>\\n')\n\nmeson uses the ciso646 header, so I would think we should use that as well.\n\n\n\n> +\n> +stdlib_msg = 'unknown'\n> +\n> +if libcxx_ver != ''\n\nI would just use `cpp.has_header_symbol('ciso646', '_LIBCPP_VERSION')`\nsince you're only really interested in the existence.\n\n\n> +  cxx_stdlib = 'libc++'\n> +elif glibcxx_ver != ''\n\nSimilar thing here.\n\n\n> +  # __GLIBCXX__ is usually a yyyymmdd date code\n> +  cxx_stdlib = 'libstdc++'\n> +endif\n> +\n> +message('Detected C++ standard library: ' + cxx_stdlib)\n> \n>   if cc.get_id() == 'clang'\n>       if cc.version().version_compare('<9')\n> @@ -138,16 +155,9 @@ if cc.get_id() == 'clang'\n>               ]\n>           endif\n>       endif\n> -\n> -    # Use libc++ by default if available instead of libstdc++ when compiling\n> -    # with clang.\n> -    if cc.find_library('c++', required : false).found()\n> -        cpp_arguments += [\n> -            '-stdlib=libc++',\n> -        ]\n> -        cxx_stdlib = 'libc++'\n> -    endif\n> -\n> +    cpp_arguments += [\n> +        '-stdlib=' + cxx_stdlib,\n> +    ]\n\nI think this can be dropped, no?\n\n\nRegards,\nBarnabás Pőcze\n\n\n>       cpp_arguments += [\n>           '-Wextra-semi',\n>           '-Wthread-safety',","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 39A77BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Oct 2025 08:28:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 14ED760714;\n\tMon, 27 Oct 2025 09:28:07 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D30F60453\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Oct 2025 09:28:06 +0100 (CET)","from [192.168.33.25] (185.182.215.162.nat.pool.zt.hu\n\t[185.182.215.162])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 75A00664;\n\tMon, 27 Oct 2025 09:26:18 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"rU2IJ6tE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761553578;\n\tbh=tZSneqvvS7JGA0FO7Z9H3x6z0AyUok6Knakj/IqmULs=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=rU2IJ6tEU7OWzLV2EkfzSk6x+CHp6RiHrVvqeLF5uapY+h0feRsuAxnahIwsU1XMv\n\tbYd1aeS1IsUyVs3QRkYEBJ7qKZoaqx1nB5H0mqqrKuznizRvhklaM9p08j/fDrp3xs\n\t9vd3Qf94fAItxE7c84Z49ARnmr/aRt7uhAXPfJwM=","Message-ID":"<b9f05c72-666a-4cb1-a39c-7112fe355049@ideasonboard.com>","Date":"Mon, 27 Oct 2025 09:28:02 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] libcamera: Do not assume libc++ with clang","To":"Khem Raj <raj.khem@gmail.com>, libcamera-devel@lists.libcamera.org","References":"<J3LWBAfRv6CCScJSaiPkbWgM8Ir61DdBf-XB4wNjkf-Hx5YXYicIipE3lO5F849BLKUcMR7zNgGx7HZ0Z5a85A==@protonmail.internalid>\n\t<20251024184009.740860-1-raj.khem@gmail.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20251024184009.740860-1-raj.khem@gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]