我想在使用C ++的基于ROS的项目中使用VLC库。我使用QT Creator作为代码编辑器。
我尝试按照以下教程实现mp3文件的简单播放: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'
当然我在文件中添加了#include "vlc/vlc.h"
。此外,我按照http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries上的说明确保添加链接器的引用。这是我添加到cmakelist.txt文件中的内容:
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能够编译文件。它还能够找到LIBVLC库。这是make的输出的一部分:
- 找到LibVLC include-dir路径:/ usr / include - 找到LibVLC库路径:/usr/lib/libvlc.so - 找到LibVLCcore库路径:/usr/lib/libvlccore.so - 发现LibVLC版本:1.1.12(搜索:0.0) - 配置完成 - 生成完成CMake警告:项目未使用手动指定的变量:
CMAKE_TOOLCHAIN_FILE
但我仍然收到上述错误消息......任何人都可以帮助我吗?
答案 0 :(得分:0)
看起来已正确找到VLC库,但您需要将它们实际链接到您的可执行文件中。
您可以通过target_link_libraries
命令执行此操作。例如:
set(LIBS ${LIBS} ${LIBVLC_LIBRARIES})
add_executable(MyExe ${TheSources})
target_link_libraries(MyExe ${LIBS})
答案 1 :(得分:0)
这可能是由于体系结构不匹配引起的-有关更多详细信息,请参见我的答案here。