linux 使用Cargo编译基于sdl的crate会导致链接器错误(sdl 2,pix-engine)[重复]

balp4ylt  于 2023-06-29  发布在  Linux
关注(0)|答案(1)|浏览(142)

此问题已在此处有答案

/usr/bin/ld: cannot find -lXinerama when compiling window manager(1个答案)
5天前关闭。
我运行的是Ubuntu 20.04.6,通过rustup安装脚本(rustup1.26.0)安装了cargo 1.70.0
运行cargo run与pix-engine示例程序粘贴到main.rs给我这个错误

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH= // trim (massive list of environment variables)
  = note: /usr/bin/ld: cannot find -lSDL2
          /usr/bin/ld: cannot find -lSDL2_mixer
          /usr/bin/ld: cannot find -lSDL2_image
          /usr/bin/ld: cannot find -lSDL2_ttf
          /usr/bin/ld: cannot find -lSDL2_gfx
          collect2: error: ld returned 1 exit status

我尝试重新安装build-essential,我尝试重新安装rustup(确保它实际上删除了cargo二进制文件)
我还尝试了sdl 2库(使用示例程序),得到了同样的错误,但

// trim
  = note: /usr/bin/ld: cannot find -lSDL2
          collect2: error: ld returned 1 exit status

所以sdl 2也抛出链接器错误,只是更少。

9nvpjoqh

9nvpjoqh1#

我在apt中搜索sdl 2包,直到我发现了这个:

$ apt search libsdl2
Sorting... Done
Full Text Search... Done
libsdl2-2.0-0/focal,now 2.0.10+dfsg1-3 amd64 [installed]
  Simple DirectMedia Layer

libsdl2-dev/focal,now 2.0.10+dfsg1-3 amd64 [installed]
  Simple DirectMedia Layer development files

libsdl2-doc/focal,focal 2.0.10+dfsg1-3 all
  Reference manual for libsdl2

libsdl2-gfx-1.0-0/focal,now 1.0.4+dfsg-3 amd64 [installed,automatic]
  drawing and graphical effects extension for SDL2

libsdl2-gfx-dev/focal,now 1.0.4+dfsg-3 amd64 [installed]
  development files for SDL2_gfx

libsdl2-gfx-doc/focal,focal 1.0.4+dfsg-3 all
  documentation files for SDL2_gfx

libsdl2-image-2.0-0/focal,now 2.0.5+dfsg1-2 amd64 [installed,automatic]
  Image loading library for Simple DirectMedia Layer 2, libraries

libsdl2-image-dev/focal,now 2.0.5+dfsg1-2 amd64 [installed]
  Image loading library for Simple DirectMedia Layer 2, development files

libsdl2-mixer-2.0-0/focal,now 2.0.4+dfsg1-2build1 amd64 [installed,automatic]
  Mixer library for Simple DirectMedia Layer 2, libraries

libsdl2-mixer-dev/focal,now 2.0.4+dfsg1-2build1 amd64 [installed]
  Mixer library for Simple DirectMedia Layer 2, development files

libsdl2-net-2.0-0/focal 2.0.1+dfsg1-4 amd64
  Network library for Simple DirectMedia Layer 2, libraries

libsdl2-net-dev/focal 2.0.1+dfsg1-4 amd64
  Network library for Simple DirectMedia Layer 2, development files

libsdl2-ttf-2.0-0/focal,now 2.0.15+dfsg1-1 amd64 [installed,automatic]
  TrueType Font library for Simple DirectMedia Layer 2, libraries

libsdl2-ttf-dev/focal,now 2.0.15+dfsg1-1 amd64 [installed]
  TrueType Font library for Simple DirectMedia Layer 2, development files

当我(通过apt)安装libsdl2-dev时,当我重新编译时,错误的/usr/bin/ld: cannot find -lSDL2部分消失了,所以我继续安装libsdl2-mixer-devlibsdl2-image-devlibsdl2-ttf-devlibsdl2-gfx-dev
在那之后,它编译和工作完美!
所以看起来
/usr/bin/ld: cannot find -lSDL2链接器错误已通过安装libsdl2-dev修复,
libsdl2-mixer-dev-lSDL2_mixer链接器错误,
等等的。
这也解决了我在sdl 2机箱上遇到的同样的问题。
P.S.我用的是sdl 2 0.35.2和pix-engine 0.7.0,目前最新的版本

相关问题