diff --git a/arch/posix/CMakeLists.txt b/arch/posix/CMakeLists.txt index bc06cecac27..74a0c9e2617 100644 --- a/arch/posix/CMakeLists.txt +++ b/arch/posix/CMakeLists.txt @@ -99,11 +99,13 @@ elseif (CONFIG_NATIVE_LIBRARY) get_filename_component(COMPILER_OWN_INCLUDE_PATH "${_OUTPUT}" DIRECTORY) # Do not use the C library from this compiler/host, - # but still use the basic compiler headers + # but still use the basic compiler headers, + # remove all operating system specific predefined macros, # no_builtin to avoid the compiler using builtin replacements for std library functions zephyr_compile_options( -nostdinc -isystem ${COMPILER_OWN_INCLUDE_PATH} + "SHELL:-include ${ZEPHYR_BASE}/arch/posix/include/undef_system_defines.h" $ $ ) diff --git a/arch/posix/include/undef_system_defines.h b/arch/posix/include/undef_system_defines.h new file mode 100644 index 00000000000..d7384e403a6 --- /dev/null +++ b/arch/posix/include/undef_system_defines.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Undefine all system-specific macros defined internally, by the compiler. + * Run 'gcc -dM -E - < /dev/null | sort' to get full list of internally + * defined macros. + */ + +#undef __gnu_linux__ +#undef __linux +#undef __linux__ +#undef linux + +#undef __unix +#undef __unix__ +#undef unix