1

I want to use the VLC library in a ROS-based project using C++. I am using QT Creator as code editor.

I tried to follow the following tutorial to implement a simple playback of a mp3 file: A simple C program to play mp3 using libvlc

Since then I'm getting the following exceptions:
undefined reference to `libvlc_new'
undefined reference to `libvlc_media_new_path'
undefined reference to `libvlc_media_player_new_from_media'
undefined reference to `libvlc_media_release'
undefined reference to `libvlc_media_player_play'
undefined reference to `libvlc_media_player_stop'
undefined reference to `libvlc_media_player_release'
undefined reference to `libvlc_release'
collect2: ld returned 1 exit status
make[2]: *** [../bin/my_face_tracker_demo] Error 1
make[1]: *** [CMakeFiles/my_face_tracker_demo.dir/all] Error 2
make: *** [all] Error 2
The process "/usr/bin/make" exited with code 2.
Error while building project my_qbo_interaction (target: Desktop)
When executing build step 'Make'

Of course I added #include "vlc/vlc.h" to the file. Furthermore, I followed the instructions to make sure I add the references for the linker. This is what I added to the cmakelist.txt-file:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(LIBVLC REQUIRED)
include_directories(${LIBVLC_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LIBVLC_LIBRARIES})

make is able to compile the file. It is also able to find the LIBVLC libraries. Here a part of the output from make:

-- Found LibVLC include-dir path: /usr/include -- Found LibVLC library path:/usr/lib/libvlc.so -- Found LibVLCcore library path:/usr/lib/libvlccore.so -- Found LibVLC version: 1.1.12 (searched for: 0.0) -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project:

CMAKE_TOOLCHAIN_FILE

But I still get the above error messages... Can anybody help me?

hacker1024
  • 3,186
  • 1
  • 11
  • 31
stromflut
  • 186
  • 1
  • 9

3 Answers3

0

It looks like the VLC libraries have been correctly found, but you need to actually link them into your executable.

You do this via the target_link_libraries command. For example:

set(LIBS ${LIBS} ${LIBVLC_LIBRARIES})
add_executable(MyExe ${TheSources})
target_link_libraries(MyExe ${LIBS})
Fraser
  • 74,704
  • 20
  • 238
  • 215
  • This already seems pretty good. I'm just very new into the C++/Linux world. How do I have to set "MyExe" and the other variables? I tried to add the following: add_executable(LIBVLC ${CMAKE_SOURCE_DIR}) target_link_libraries(LIBVLC ${LIBVLC_LIBRARIES}) Didn't help :-( – stromflut May 07 '13 at 22:42
  • 1
    Ah right. The [`add_executable`](http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:add_executable) command takes the name of your exe as the first argument, then it needs the list of source files which are going to be compiled into the exe. In your example, you're passing the path to the root of your project as the list of files - `${CMAKE_SOURCE_DIR}` is the directory where your top-level CMakeLists.txt lives! Also, "LIBVLC" is quite a strange name for an executable - I'd recommend you change that too :-) Anyway, you need to have something like `add_executable(MyExe src/main.cpp)` – Fraser May 07 '13 at 22:47
  • If you have several files to compile into the exe, just list them all. You can gather them up into a variable (like `${TheSources}` in my example). e.g. `set(TheSources src/a.cpp src/b.cpp src/main.cpp)` then `add_executable(MyExe ${TheSources})`. – Fraser May 07 '13 at 22:50
  • I couldn't make it work, I found a different solution that fits for me: System Call to mpg321 to play sound. thanks anyway for your help! – stromflut May 15 '13 at 11:34
0

This can be caused by an architecture mismatch - you can see my answer here for more details.

hacker1024
  • 3,186
  • 1
  • 11
  • 31
0

I wanted to do the same thing. For anyone else that got stuck.

copy the https://github.com/vlc-qt/vlc-qt/blob/master/cmake/FindLIBVLC.cmake and put it into a new directory cmake/Modules under the root of your project.

cmake should then use:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(LIBVLC REQUIRED)

if you check the FindLIBVLC.cmake from above the name of the dirs are not

include_directories(${LIBVLC_INCLUDE_DIRS})
set(LIBS ${LIBS} ${LIBVLC_LIBRARIES})

They are:

${LIBVLC_INCLUDE_DIR} and ${LIBVLC_LIBRARY}