Advertisement

编译LVGL遇到的问题及解决方式

阅读量:

问题1: 编译选项报错, 未识别 -Wshift-negative-value 选项

复制代码
    Building project file: main/src/main.c
    Building project file: main/src/mouse_cursor_icon.c
    cc: error: unrecognized command line option ‘-Wshift-negative-value’
    cc: error: unrecognized command line option ‘-Wshift-negative-value’
    Makefile:57: recipe for target 'build/obj/main/src/main.o' failed
    make: *** [build/obj/main/src/main.o] Error 1
    make: *** Waiting for unfinished jobs....
    Makefile:57: recipe for target 'build/obj/main/src/mouse_cursor_icon.o' failed
    make: *** [build/obj/main/src/mouse_cursor_icon.o] Error 1
    
    

原因: -Wshift-negative-value 选项的作用是检查左移操作(<<)中可能出现的负数。
当一个负数被左移时,结果通常是未定义的。在某些硬件和编译器实现中,这样的操作可能产生一个未定义的结果或者异常。为了防止这种情况,GCC 提供了一个警告来帮助开发者检测这样的潜在问题。
比如:

复制代码
    int x = -5;  
    x <<= 2;  // This operation is not defined for negative numbers
    
    

所以, 编译的时候出现上面的问题是因为gcc版本过低导致, 升级gcc和g++即可

复制代码
    # 添加ppa资源库
    sudo add-apt-repository ppa:ubuntu-toolchain-r/test
    sudo apt-get update
    sudo apt-get install gcc-9
     sudo apt-get install g++-9
     cd /usr/bin
     sudo rm gcc g++
     sudo ln -s gcc-9   gcc
     sudo ln -s g++-9   g++
    # 安装好后检查版本
     gcc  -v
     g++  -v
    
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-17/hFArvq7MlLk5cZIRgz9VGnT268bW.png)

问题2

复制代码
    dpkg: dependency problems prevent configuration of code:
     code depends on libnss3 (>= 2:3.30); however:
      Version of libnss3:amd64 on system is 2:3.28.4-0ubuntu0.16.04.14.
    
    dpkg: error processing package code (--install):
     dependency problems - leaving unconfigured
    
    

libnss3 版本库太旧。 这个问题是因为在Ubuntu中安装vscode时遇到的,其实这个vscode可以完全不用装。不过这个libnss3版本旧的问题,有必要解决
解决:

复制代码
    # 下载高版本的库
    wget http://archive.ubuntu.com/ubuntu/pool/main/n/nss/libnss3_3.49.1-1ubuntu1_amd64.deb
    # 安装
    sudo dpkg -i libnss3_3.49.1-1ubuntu1_amd64.deb
    
    

下载lvgl代码库,编译demo

复制代码
    git clone --recursive https://gitee.com/JavonPeng/lvgl_vscode_sdl.git 
    git submodule update --init --recursive
    sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev
    
    cd   lvgl_vscode_sdl
    make
    cd build/bin
    ./demo # demo启动
    
    

全部评论 (0)

还没有任何评论哟~