Skip to content

Commit d8b85b6

Browse files
committed
Do not append -static-libc++ to linker_args when libcxx is used
Clang has a long standing bug where it will try to mix c++ libraries instead of erroring out early or transparently linking against libcxx statically instead. Signed-off-by: Alfred Wingate <parona@protonmail.com>
1 parent e68fc75 commit d8b85b6

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/meson.build

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,23 @@ if is_unixy
167167
endif
168168
endif
169169

170-
link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro', '-Wl,--exclude-libs,ALL', '-lGL', '-static-libstdc++'])
170+
link_args = cpp.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro', '-Wl,--exclude-libs,ALL', '-lGL'])
171+
172+
# Approach for libc++ detection taken from https://github.com/mesonbuild/meson/commit/675b47b0692131fae974298829ba807d730ab098
173+
# Rationale for the approach is explained in this SO answer https://stackoverflow.com/a/31658120
174+
if cpp.has_header('<version>')
175+
header = 'version'
176+
else
177+
header = 'ciso646'
178+
endif
179+
is_libcxx = cpp.has_header_symbol(header, '_LIBCPP_VERSION')
180+
181+
# https://github.com/llvm/llvm-project/issues/38622
182+
if is_libcxx
183+
message('Detected libcxx, not appending -static-libstc++ to linker arguments')
184+
else
185+
link_args+=['-static-libstdc++']
186+
endif
171187

172188
mangohud_static_lib = static_library(
173189
'MangoHud',

0 commit comments

Comments
 (0)