diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index e31e0eb7c2..ba790789f1 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -13,14 +13,16 @@ endif() set_ifndef(LINKERFLAGPREFIX -Wl) -if(CONFIG_EXCEPTIONS) - # When building with C++ Exceptions, it is important that crtbegin and crtend - # are linked at specific locations. - # The location is so important that we cannot let this be controlled by normal - # link libraries, instead we must control the link command specifically as - # part of toolchain. - set(CMAKE_CXX_LINK_EXECUTABLE - " ${LIBGCC_DIR}/crtbegin.o -o ${LIBGCC_DIR}/crtend.o") +if(NOT "${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "host") + if(CONFIG_EXCEPTIONS) + # When building with C++ Exceptions, it is important that crtbegin and crtend + # are linked at specific locations. + # The location is so important that we cannot let this be controlled by normal + # link libraries, instead we must control the link command specifically as + # part of toolchain. + set(CMAKE_CXX_LINK_EXECUTABLE + " ${LIBGCC_DIR}/crtbegin.o -o ${LIBGCC_DIR}/crtend.o") + endif() endif() # Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen}