  | 
      
        
          1樓
          巨大八爪鱼
          2025-3-13 19:42
          
          
           
         
        【症狀】 編譯內核模塊時,只顯示最底部的Error,不顯示任何C語言的錯誤信息。 [oct1158@fed41-bh8f7e0 first]$ make make -C /home/oct1158/Documents/Code/C/luckfox-pico/sysdrv/source/kernel M=/home/oct1158/Documents/Code/C/driver_test/first modules ARCH=arm CROSS_COMPILE=/home/oct1158/Documents/Code/C/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- make[2]: *** [scripts/Makefile.build:273: /home/oct1158/Documents/Code/C/driver_test/first/test.o] Error 1 make[1]: *** [Makefile:1935: /home/oct1158/Documents/Code/C/driver_test/first] Error 2 make: *** [Makefile:7: build] Error 2 [oct1158@fed41-bh8f7e0 first]$
  【原因】 make命令中含有s字符,導致進入了安靜模式。 make -C /home/oct1158/Documents/Code/C/luckfox-pico/sysdrv/source/kernel M=/home/oct1158/Documents/Code/C/driver_test/first modules ARCH=arm CROSS_COMPILE=/home/oct1158/Documents/Code/C/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- 在這句命令中,「driver_test」就含有s字符,所以就會觸發安靜模式。
  $(MAKEFLAGS)變量的值: rR --no-print-directory -- CROSS_COMPILE=/home/oct1158/Documents/Code/C/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- ARCH=arm M=/home/oct1158/Documents/Code/C/driver_test/first
  $(filter-out --%,$(MAKEFLAGS))表達式的值: rR CROSS_COMPILE=/home/oct1158/Documents/Code/C/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- ARCH=arm M=/home/oct1158/Documents/Code/C/driver_test/first 可見這個表達式含有s字符。
  【解決辦法】 註釋掉內核根目錄的Makefile文件裏面的下面三句話。 ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)   quiet=silent_ endif 禁止進入安靜模式。
  
       | 
    
    
        | 
      
        
          2樓
          巨大八爪鱼
          2025-3-13 19:43
          
          
           
         
        修改後就有錯誤信息輸出了。 [oct1158@fed41-bh8f7e0 first]$ make make -C /home/oct1158/Documents/Code/C/luckfox-pico/sysdrv/source/kernel M=/home/oct1158/Documents/Code/C/driver_test/first modules ARCH=arm CROSS_COMPILE=/home/oct1158/Documents/Code/C/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-   CC [M]  /home/oct1158/Documents/Code/C/driver_test/first/test.o /home/oct1158/Documents/Code/C/driver_test/first/test.c: In function 'mytestdriver_probe': /home/oct1158/Documents/Code/C/driver_test/first/test.c:10:9: error: implicit declaration of function 'devm_gpiod_get'; did you mean 'em_pd_get'? [-Werror=implicit-function-declaration]   gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_HIGH); // led on          ^~~~~~~~~~~~~~          em_pd_get /home/oct1158/Documents/Code/C/driver_test/first/test.c:10:42: error: 'GPIOD_OUT_HIGH' undeclared (first use in this function)   gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_HIGH); // led on                                           ^~~~~~~~~~~~~~ /home/oct1158/Documents/Code/C/driver_test/first/test.c:10:42: note: each undeclared identifier is reported only once for each function it appears in /home/oct1158/Documents/Code/C/driver_test/first/test.c: In function 'mytestdriver_remove': /home/oct1158/Documents/Code/C/driver_test/first/test.c:28:3: error: implicit declaration of function 'gpiod_set_value'; did you mean 'bitmap_set_value8'? [-Werror=implicit-function-declaration]    gpiod_set_value(gpio, 0); // led off    ^~~~~~~~~~~~~~~    bitmap_set_value8 cc1: all warnings being treated as errors make[2]: *** [scripts/Makefile.build:273: /home/oct1158/Documents/Code/C/driver_test/first/test.o] Error 1 make[1]: *** [Makefile:1935: /home/oct1158/Documents/Code/C/driver_test/first] Error 2 make: *** [Makefile:7: build] Error 2 [oct1158@fed41-bh8f7e0 first]$
  
       | 
    
    
        | 
      
        
          3樓
          巨大八爪鱼
          2025-3-13 19:45
          
          
           
         
        事實上,在編譯內核模塊時,就算make命令沒帶CROSS_COMPILE=參數,M=參數肯定是必須帶的。我們很難保證M參數裏面沒有s這個字符。 
       | 
    
    
        | 
      
        
          4樓
          巨大八爪鱼
          2025-3-13 19:47
          
          
           
         
        修改C語言的錯誤後: [oct1158@fed41-bh8f7e0 first]$ make make -C /home/oct1158/Documents/Code/C/luckfox-pico/sysdrv/source/kernel M=/home/oct1158/Documents/Code/C/driver_test/first modules ARCH=arm CROSS_COMPILE=/home/oct1158/Documents/Code/C/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-   CC [M]  /home/oct1158/Documents/Code/C/driver_test/first/test.o   MODPOST /home/oct1158/Documents/Code/C/driver_test/first/Module.symvers   LD [M]  /home/oct1158/Documents/Code/C/driver_test/first/test.ko [oct1158@fed41-bh8f7e0 first]$ 編譯通過了,CC MODPOST LD等字樣也能正常顯示了。
  
       |