c++ - 使用 CMake 构建 GStreamer 会导致 SDP 和 WebRTC 无法解析的外部符号错误

标签 c++ cmake gstreamer glib

我正在使用 CMake 构建一个 C++ GStreamer 项目,它依赖于 GStreamer、GLIB、Libsoup 和 json-glib。我是 CMake 的新手,在设置我的项目时遇到了问题。我已经设法包含了许多依赖项,但有些似乎仍未解决,即使它们是 GStreamer 的一部分。除 SDP 和 WebRTC 外,所有 GStreamer 方法和类型都已解析。据我了解,它们是 GStreamer 的一部分,并且也位于 GMake 正确“找到”的目录内。

这些是在尝试构建项目时发生的错误。

[build] error LNK2019: unresolved external symbol __imp_gst_sdp_message_new referenced in function "void __cdecl soup_websocket_message_cb(struct _SoupWebsocketConnection *,enum SoupWebsocketDataType,struct _GBytes *,void *)" (?soup_websocket_message_cb@@YAXPEAU_SoupWebsocketConnection@@W4SoupWebsocketDataType@@PEAU_GBytes@@PEAX@Z)
[build] error LNK2019: unresolved external symbol __imp_gst_sdp_message_parse_buffer referenced in function "void __cdecl soup_websocket_message_cb(struct _SoupWebsocketConnection *,enum SoupWebsocketDataType,struct _GBytes *,void *)" (?soup_websocket_message_cb@@YAXPEAU_SoupWebsocketConnection@@W4SoupWebsocketDataType@@PEAU_GBytes@@PEAX@Z)
[build] error LNK2019: unresolved external symbol __imp_gst_sdp_message_as_text referenced in function "void __cdecl on_offer_created_cb(struct _GstPromise *,void *)" (?on_offer_created_cb@@YAXPEAU_GstPromise@@PEAX@Z)
[build] error LNK2019: unresolved external symbol __imp_gst_webrtc_session_description_get_type referenced in function "void __cdecl on_offer_created_cb(struct _GstPromise *,void *)" (?on_offer_created_cb@@YAXPEAU_GstPromise@@PEAX@Z)
[build] error LNK2019: unresolved external symbol __imp_gst_webrtc_session_description_new referenced in function "void __cdecl soup_websocket_message_cb(struct _SoupWebsocketConnection *,enum SoupWebsocketDataType,struct _GBytes *,void *)" (?soup_websocket_message_cb@@YAXPEAU_SoupWebsocketConnection@@W4SoupWebsocketDataType@@PEAU_GBytes@@PEAX@Z)
[build] error LNK2019: unresolved external symbol __imp_gst_webrtc_session_description_free referenced in function "void __cdecl on_offer_created_cb(struct _GstPromise *,void *)" (?on_offer_created_cb@@YAXPEAU_GstPromise@@PEAX@Z)

这是我的CMakeLists.txt

# CMakeList.txt : CMake project for stream-project, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)

project (stream-project LANGUAGES CXX)

# Packages
find_package(PkgConfig REQUIRED)

# Add source to this project's executable.
add_executable (${PROJECT_NAME} "main.cpp" "main.h")

# Search all modules that we so desire to use and "include_directories"
pkg_search_module(GST REQUIRED gstreamer-1.0 gstreamer-sdp-1.0 gstreamer-video-1.0 gstreamer-app-1.0 gstreamer-webrtc-1.0)
pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_search_module(LIBSOUP REQUIRED libsoup-2.4)
pkg_search_module(JSONGLIB REQUIRED json-glib-1.0)

include_directories(
    ${GST_INCLUDE_DIRS}
    ${GLIB_INCLUDE_DIRS}
    ${LIBSOUP_INCLUDE_DIRS}
    ${JSONGLIB_INCLUDE_DIRS}
)

# Link target directories and libraries
target_link_directories(${PROJECT_NAME} PRIVATE
    ${GST_LIBRARY_DIRS}
    ${GLIB_LIBRARY_DIRS}
    ${LIBSOUP_LIBRARY_DIRS}
    ${JSONGLIB_LIBRARY_DIRS}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
    ${GST_LIBRARIES}
    ${GLIB_LIBRARIES}
    ${LIBSOUP_LIBRARIES}
    ${JSONGLIB_LIBRARIES}
)

message(STATUS ${GST_INCLUDE_DIRS})

最佳答案

我已经通过使用我在网上找到的预制查找脚本设法解决了这个问题。

https://chromium.googlesource.com/external/Webkit/+/master/Source/cmake/FindGStreamer.cmake

它会创建所有必要的定义,然后我将其包含并链接。

这些是 FindGStreamer.cmake 文件中指定的默认值

FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gst/app/gstappsink.h gstapp-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gst/audio/audio.h gstaudio-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gst/fft/gstfft.h gstfft-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gst/pbutils/pbutils.h gstpbutils-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_VIDEO gstreamer-video-1.0 gst/video/video.h gstvideo-1.0)

我扩展了上面的内容:

FIND_GSTREAMER_COMPONENT(GSTREAMER_SDP gstreamer-sdp-1.0 gst/sdp/sdp.h gstsdp-1.0)
FIND_GSTREAMER_COMPONENT(GSTREAMER_WEBRTC gstreamer-webrtc-1.0 gst/webrtc/webrtc.h gstwebrtc-1.0)

关于c++ - 使用 CMake 构建 GStreamer 会导致 SDP 和 WebRTC 无法解析的外部符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71575173/

相关文章:

C++:递归地将参数类型与类模板类型匹配

macos - Homebrew:无法符号链接(symbolic link),/usr/local/share/man/man7 不可写

c++ - 如何在cmake中添加链接器目录?

android - RTSP 播放器性能

gstreamer - 队列元素在Gstreamer管道中的作用

c++ - 函数 'Summation' 的参数太少

c++ - C++ Hello World 的简单构建

c++ - 如何在 C++ 中以追加模式清除文件

build - Cmake 不尊重 CMAKE_INSTALL_PREFIX 的值

android - GStreamer android 教程不工作