c++ - 未定义对 'libvlc_new"的引用但链接正确?

标签 c++ linux qt cmake ros

我想在使用 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"。此外,我关注了the instructions确保我添加了链接器的引用。这是我添加到 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 的部分输出:

-- 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

但我仍然收到上述错误消息...有人可以帮助我吗?

最佳答案

看起来 VLC 库已正确找到,但您需要实际将它们链接到可执行文件中。

您可以通过 target_link_libraries 执行此操作命令。例如:

set(LIBS ${LIBS} ${LIBVLC_LIBRARIES})
add_executable(MyExe ${TheSources})
target_link_libraries(MyExe ${LIBS})

关于c++ - 未定义对 'libvlc_new"的引用但链接正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16429338/

相关文章:

c++ - 通过void函数获取数据成员(c++)

mysql - Linux bash MySQL 载入文件

c++ - Qt单元测试输出字符串长度截断

c++ - 在 QQuickItem 上打开 QFileDialog

c++ - C++ 可执行文件 : While loop and If/Else If/Else 的问题

c++ - 替换字符串中的重复项

linux - Raspberry Pi - No-IP DNS 不工作

linux - 将光盘 (HD) 路径加载到内存 (Minix)

c++ - QT QImage,如何提取RGB?

c++ - C++代码中的错误可能是指针未指向任何东西