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

Building GStreamer with CMake causes SDP & WebRTC unresolved external symbol errors

我正在使用 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

它创建了所有必要的定义,然后我将其包括在内 link。

这些是 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)