0

I'm running Ubuntu 20.04.6, with cargo 1.70.0 installed via the rustup installer script (rustup 1.26.0)

running cargo run with the the pix-engine example program pasted into main.rs gave me this error

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

I tried reinstalling build-essential, I tried reinstalling rustup (making sure it actually removed the cargo binary)

I also tried the sdl2 library (with the example program) and got the same error but with

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

at the end. so sdl2 was throwing linker errors, too, just fewer.

cafce25
  • 15,907
  • 4
  • 25
  • 31
joeman
  • 1
  • 2

1 Answers1

0

I searched around apt for sdl2 packages until i found this:

$ 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

When I (via apt) installed libsdl2-dev the /usr/bin/ld: cannot find -lSDL2 part of the error disappeared when I recompiled, so I continued on and installed libsdl2-mixer-dev, libsdl2-image-dev, libsdl2-ttf-dev and libsdl2-gfx-dev

And after that it compiled and worked perfectly!

So it would seem that

/usr/bin/ld: cannot find -lSDL2 linker error is fixed by installing libsdl2-dev,

-lSDL2_mixer linker error with libsdl2-mixer-dev,

etc.

This also fixed the same problem with the sdl2 crate I was having.

P.S. I used sdl2 0.35.2 and pix-engine 0.7.0, the current latest versions

cafce25
  • 15,907
  • 4
  • 25
  • 31
joeman
  • 1
  • 2
  • 3
    Just for form's sake, you should probably move the answer part of the question post to the actual answer.. – Caesar Jun 23 '23 at 02:08