Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 核心編譯 ld: cannot find /ubuntu/omnibook/sections.lds 錯誤修正:Makefile 路徑修正

編輯:Linux 教學

編譯 ubuntu/omnibook 子系統時連結器找不到 sections.lds,原因是 Makefile 使用 $(src) 變數在外部建構樹中解析錯誤。修正路徑變數即可。

錯誤訊息


ld: cannot find /ubuntu/omnibook/sections.lds: No such file or directory

修正方法一:在 Makefile 早期定義 PWD

  1. 編輯 /usr/src/linux-source-2.6.32/ubuntu/omnibook/Makefile
  2. 找到:

ifeq ($(KERNELRELEASE),)
# Support for direct Makefile invocation
  1. 在此前插入:PWD=$(shell pwd)

修正方法二:直接修正 EXTRA_LDFLAGS 行 (約第 160-161 行)


# 原始 (錯誤)
#EXTRA_LDFLAGS += $(src)/sections.lds
EXTRA_LDFLAGS += $(PWD)/ubuntu/omnibook/sections.lds

改為兩種任一:


// 方法 A:啟用 PWD 定義
#EXTRA_LDFLAGS += $(src)/sections.lds
PWD = $(shell pwd)
EXTRA_LDFLAGS += $(PWD)/ubuntu/omnibook/sections.lds

// 方法 B:回退使用 $(src) (若在核心樹內建構)
EXTRA_LDFLAGS += $(src)/sections.lds
#EXTRA_LDFLAGS += $(PWD)/ubuntu/omnibook/sections.lds

原理

  • $(src) 為核心建構系統內部變數,僅在核心樹內 make 時有效
  • 外部模組建構 (make -C /lib/modules/$(uname -r)/build M=$PWD) 時 $(src) 解析為空/錯誤路徑
  • $(PWD) 或 $(shell pwd) 取得當前絕對路徑,確保連結器找到 sections.lds

驗證


make clean && make

連結通過,模組 .ko 產出成功。

Copyright © Windows教程網 All Rights Reserved