meson icon indicating copy to clipboard operation
meson copied to clipboard

clike compilers: Add default sysroot include directory

Open thierryreding opened this issue 3 years ago • 3 comments

When building against a sysroot, meson currently fails to detect that the /usr/include directory within that sysroot is a default search directory. This causes the directory to be added with -isystem to the compiler command-line which in turn causes include lookup failures.

A minimal test case to reproduce this behaviour is:

$ echo -e "#include \nint main() { return 0; }" > foo.cpp $ g++ --sysroot / -isystem /usr/include -o foo foo.cpp In file included from /usr/include/c++/11.1.0/ext/string_conversions.h:41, from /usr/include/c++/11.1.0/bits/basic_string.h:6594, from /usr/include/c++/11.1.0/string:55, from /usr/include/c++/11.1.0/bits/locale_classes.h:40, from /usr/include/c++/11.1.0/bits/ios_base.h:41, from /usr/include/c++/11.1.0/ios:42, from /usr/include/c++/11.1.0/ostream:38, from /usr/include/c++/11.1.0/iostream:39, from foo.cpp:1: /usr/include/c++/11.1.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory 75 | #include_next <stdlib.h> | ^~~~~~~~~~ compilation terminated.

Omitting the -isystem /usr/include option avoids that error because it doesn't mess up the include directory search order.

Fix this by adding the sysroot's /usr/include directory to the list of default search directories when a sysroot is detected. This ensures that any occurrences of it are filtered out and the include directory search order is left alone.

thierryreding avatar Feb 11 '22 16:02 thierryreding

@dcbaker any comments on this?

thierryreding avatar Mar 02 '22 15:03 thierryreding

@dcbaker I'm still running into this issue with sysrooted cross builds, can you take a look at this?

thierryreding avatar Nov 30 '22 15:11 thierryreding

Also, I'm sorry I missed this before. I haven't been doing a good job of keeping my github notifications manageable :/

dcbaker avatar Nov 30 '22 17:11 dcbaker