2

I have installed "libsdl1.2-dev" and "libvlc" (with sudo apt-get install blah) in Raspbian on my Raspberry Pi, I'm using gcc to compile the example project from https://wiki.videolan.org/LibVLC_SampleCode_SDL/

This is my compile command:

gcc -fpermissive test.cpp -lvlc -lsdl1.2-dev -o test

It seems to compile (after I added -fpermissive and manually placed the vlc headers in usr/include/vlc) the error seems to happen during the linking phase, I get these 2 errors;

/usr/bin/ld: cannot find -lvlc
/usr/bin/ld: cannot find -lsdl1.2-dev

I'm a bit new to Linux and I can't work out why it can't find them. I'm also unsure where it installs them by default, there seem to be a few different places they could be.

Domarius
  • 413
  • 1
  • 3
  • 13
  • 1
    Libraries are usually installed in "/usr/lib" directory, check if libvlc.so lists when you enter "$ ls -al | grep vlc" in terminal. If your library is present in a different path you need to include the library path by using the command "$export PATH=PATH:" – hungryspider Apr 02 '19 at 05:55
  • You shouldn't need to manually place headers in /usr/include. If that's necessary, something is wrong. Which headers did you need to copy? – Julius Bullinger Apr 02 '19 at 09:04
  • @AkshayVernekar Nothing lists when I type that command. And a manual inspection of /usr/lib doesn't seem to have any libvlc file or even vlc file or folder. However, when I run "sudo apt-get install vlc" I get "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." Perhaps Raspbian likes to put libraries in a different folder? How can I find out? – Domarius Apr 03 '19 at 20:40
  • 1
    @JuliusBullinger Yes it didn't seem right to have to do that. But I was trying to be a "good programmer" and first try to solve everything myself ;) I copied the full "header" folder to "/usr/include/vlc" This included 14 files such as libvlc.h, libvlc_dialog.h etc. and a plugins folder. This solved an error with gcc not being able to find "vlc/vlc.h" and got me to where I am now; linker errors. – Domarius Apr 03 '19 at 20:45
  • @Domarius, that's fine, you'll know the next time. :) General hint: You shouldn't ever have to move files around that have been installed by a package. If your build doesn't find the files, you need to it them where to find them. Although I admit it's really strange that it couldn't find them, because ``#include`` *should just work* if the files are in /usr/include/vlc. Can you run ``echo | gcc -E -Wp,-v -`` and ``gcc -print-search-dirs`` and paste the output? – Julius Bullinger Apr 04 '19 at 08:15
  • @JuliusBullinger thanks for help! The answer from "Nikos C." pointed out I should have installed "libvlc-dev", not just "vlc", and he got the thing finally compiling by way of including the pkg-config command :) – Domarius Apr 04 '19 at 23:10

3 Answers3

2

Use pkg-config to get the needed compile and link flags. pkg-config --cflags sdl libvlc will print the needed compilation flags, and pkg-config --libs sdl libvlc the needed link flags. You can use the $() feature of the shell to embed the output of pkg-config directly into your compile command. Also, use g++ to compile and link C++ code. gcc is for C code.

g++ $(pkg-config --cflags sdl libvlc) -fpermissive test.cpp -o test $(pkg-config --libs sdl libvlc)

The package names sdl and libvlc correspond to *.pc files that are installed in /usr/lib/pkgconfig. If no such files exist, then that means you forgot to install the -dev versions of the sdl and vlc libraries. So check if there's a libvlc-dev package you need to install. Use this:

apt-cache search vlc | grep dev

See if there's a dev package for libvlc that you need.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
  • You covered everything and I got it working. Yes I was missing the -dev version of vlc, and it stopped complaining about missing -lvlc. But also even though I had installed libsld1.2-dev, it still complained about missing -lsdl1.2-dev, or -lsdl1.2 or even -lsdl, I tried all of those variations. But using the command above (by including pkg-config in my compile command) the program actually compiled and ran successfully! And the pkg-config --libs command reveals the mysterious linker name of sdl is -lSDL - capitalised! I never would have guessed it. – Domarius Apr 04 '19 at 23:07
1

To install libraries and header files, try sudo apt-get install libvlc-dev this should install all the dependent libraries in the correct library paths. sudo apt-get install vlc is used to install the application which in your case you dont need.

hungryspider
  • 300
  • 2
  • 13
  • Thank you, that was the case. And the answer from "Nikos C." got the thing finally compiling by way of including the pkg-config command :) – Domarius Apr 04 '19 at 23:09
0

Try sudo apt-get install vlc, you're probably missing some plugins and stuff

mfkl
  • 1,914
  • 1
  • 11
  • 21
  • Yes I've done that previously, and it always returns with "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." because libvlc is already included in this version of Raspbian. – Domarius Apr 03 '19 at 20:37
  • 1
    `libvlc` does not equal `vlc` in terms of packaging (at least for ubuntu) – mfkl Apr 04 '19 at 07:49
  • You were right, I definitely didn't realise that. That solved the missing -lvlc problem, and the answer from "Nikos C." got the thing finally compiling by way of including the pkg-config command :) – Domarius Apr 04 '19 at 23:09