diff --git a/CMakeLists.txt b/CMakeLists.txt index 04d4753d1c..4c9e931730 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,7 +475,17 @@ if(CONFIG_APPLICATION_MEMORY) string(SUBSTRING ${fixed_path} 1 -1 fixed_path) endif() - list(APPEND ks "${fixed_path}lib${target_name}.a") + set(fixed_path "${fixed_path}lib${target_name}.a") + + if(CMAKE_GENERATOR STREQUAL "Ninja") + # Ninja invokes the linker from the root of the build directory + # (APPLICATION_BINARY_DIR) instead of from the build/zephyr + # directory (PROJECT_BINARY_DIR). So for linker-defs.h to get + # the correct path we need to prefix with zephyr/. + set(fixed_path "zephyr/${fixed_path}") + endif() + + list(APPEND ks ${fixed_path}) endforeach() # We are done constructing kernel_object_file_list, now we inject this diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 486f1cd0d0..3d9de4c12f 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -115,8 +115,8 @@ archives like KBuild did.*/ #endif -#define X(i, j) KERNEL_OBJECT_FILE_##i (j) -#define Y(i, j) *KERNEL_OBJECT_FILE_##i +#define X(i, j) KERNEL_OBJECT_FILE_##i (j) +#define Y(i, j) KERNEL_OBJECT_FILE_##i #define KERNEL_INPUT_SECTION(sect) \ UTIL_LISTIFY(NUM_KERNEL_OBJECT_FILES, X, sect)