diff --git a/tests/meson.build b/tests/meson.build index 781369434..7916bbca7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -167,6 +167,39 @@ endif test_override_options = ['b_sanitize=none'] if library_type == 'static' + c_compiler = meson.get_compiler('c') + searchdirs = run_command(c_compiler.cmd_array(), '-print-search-dirs', + check: true).stdout() + searchdirs_arr = searchdirs.split('\n') + searchline = 'libraries: =' + searchpaths = '' + + foreach line : searchdirs_arr + if line.startswith(searchline) + searchpaths = line.strip(searchline) + break + endif + endforeach + + if searchpaths == '' + error('could not find compiler-specific library directory') + endif + + searchpaths_arr = searchpaths.split(':') + crtpath = '' + fs = import('fs') + foreach path : searchpaths_arr + if fs.exists(path / 'crtbegin.o') + crtpath = path + break + endif + endforeach + + if crtpath == '' + error('could not find crtbegin.o/crtend.o') + endif + test_sources += files(crtpath / 'crtbegin.o', crtpath / 'crtend.o') + libc_dep = declare_dependency( include_directories: libc_include_dirs, link_with: libc_static,