首页 > 解决方案 > 使用 Cmake 构建 Gstreamer mpegts 项目

问题描述

我们正在尝试使用 Gstreamer 的 mpegts 插件使用以下 Gstreamer 示例代码https://gstreamer.freedesktop.org/documentation/mpegtsmux/mpegtsmux.html?gi-language=c录制视频流。当我们使用一切按预期编译代码时gcc mpegtstest.c -o mpegtstest `pkg-config --cflags --libs gstreamer-1.0 gstreamer-mpegts-1.0` -v ,程序记录没有问题。我们现在尝试使用cmake和编译代码makecmake正确生成但因make错误而失败。 /usr/bin/ld: cannot find -lgstreamer-mpegts-1.0.

CMakeLists.txt

##################### STANDARD HEADER #########################
cmake_minimum_required(VERSION 2.6)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "" FORCE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeHelpers/")

##################### PROJECT DEF #############################
project(mpegsttest)

################### VARIABLES #################################
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/../")

set(MPEGTS_TEST_SOURCES
    mpegtstest.c
)

####################### Targets ########################
add_executable(${CMAKE_PROJECT_NAME} ${MPEGTS_TEST_SOURCES})

################### Linked Libraries ###################

find_package(GLIB2 REQUIRED)
include_directories(${GLIB2_INCLUDE_DIRS})
include_directories("/usr/include/gio-unix-2.0")
target_link_libraries(${CMAKE_PROJECT_NAME} ${GLIB2_LIBRARIES} gobject-2.0  gio-2.0)

find_package(GStreamer REQUIRED)
include_directories(${GSTREAMER_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} ${GSTREAMER_LIBRARIES})

include_directories(${GSTREAMER-MPEGTS_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} gstreamer-mpegts-1.0)

cmake 输出

-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for one of the modules 'glib-2.0'
-- Found GLib2: glib-2.0 /usr/include/glib-2.0;/usr/lib/glib-2.0/include
-- Looking for include file glib/gregex.h
-- Looking for include file glib/gregex.h - not found
-- Looking for include file glib/gchecksum.h
-- Looking for include file glib/gchecksum.h - not found
-- Checking for module 'gstreamer-1.0 >= '
--   Found gstreamer-1.0 , version 1.6.3
-- Checking for module 'gstreamer-base-1.0 >= '
--   Found gstreamer-base-1.0 , version 1.6.3
-- Checking for module 'gstreamer-app-1.0 >= '
--   Found gstreamer-app-1.0 , version 1.6.3
-- Checking for module 'gstreamer-audio-1.0 >= '
--   Found gstreamer-audio-1.0 , version 1.6.3
-- Checking for module 'gstreamer-fft-1.0 >= '
--   Found gstreamer-fft-1.0 , version 1.6.3
-- Checking for module 'gstreamer-mpegts-1.0>=1.4.0'
--   Found gstreamer-mpegts-1.0, version 1.6.3
-- Checking for module 'gstreamer-pbutils-1.0 >= '
--   Found gstreamer-pbutils-1.0 , version 1.6.3
-- Checking for module 'gstreamer-tag-1.0 >= '
--   Found gstreamer-tag-1.0 , version 1.6.3
-- Checking for module 'gstreamer-video-1.0 >= '
--   Found gstreamer-video-1.0 , version 1.6.3
-- Found GStreamer: GSTREAMER_INCLUDE_DIRS;GSTREAMER_LIBRARIES;GSTREAMER_VERSION;GSTREAMER_BASE_INCLUDE_DIRS;GSTREAMER_BASE_LIBRARIES  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dev3lx/build/mpegts

make --trace输出

Makefile:176: target 'cmake_check_build_system' does not exist
/usr/bin/cmake -H/home/dev3lx/Development/mptestsrc -B/home/dev3lx/build/mpegts --check-build-system CMakeFiles/Makefile.cmake 0
Makefile:83: update target 'all' due to: cmake_check_build_system
/usr/bin/cmake -E cmake_progress_start /home/dev3lx/build/mpegts/CMakeFiles /home/dev3lx/build/mpegts/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
CMakeFiles/Makefile2:67: target 'CMakeFiles/mpegsttest.dir/all' does not exist
make -f CMakeFiles/mpegsttest.dir/build.make CMakeFiles/mpegsttest.dir/depend
CMakeFiles/mpegsttest.dir/build.make:112: target 'CMakeFiles/mpegsttest.dir/depend' does not exist
cd /home/dev3lx/build/mpegts && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dev3lx/Development/mptestsrc /home/dev3lx/Development/mptestsrc /home/dev3lx/build/mpegts /home/dev3lx/build/mpegts /home/dev3lx/build/mpegts/CMakeFiles/mpegsttest.dir/DependInfo.cmake --color=
Scanning dependencies of target mpegsttest
make -f CMakeFiles/mpegsttest.dir/build.make CMakeFiles/mpegsttest.dir/build
CMakeFiles/mpegsttest.dir/build.make:62: update target 'CMakeFiles/mpegsttest.dir/mpegtstest.c.o' due to: /home/dev3lx/Development/mptestsrc/mpegtstest.c /usr/include/glib-2.0/glib-object.h /usr/include/glib-2.0/glib.h /usr/include/glib-2.0/glib/deprecated/gallocator.h /usr/include/glib-2.0/glib/deprecated/gcache.h /usr/include/glib-2.0/glib/deprecated/gcompletion.h /usr/include/glib-2.0/glib/deprecated/gmain.h /usr/include/glib-2.0/glib/deprecated/grel.h /usr/include/glib-2.0/glib/deprecated/gthread.h /usr/include/glib-2.0/glib/galloca.h /usr/include/glib-2.0/glib/garray.h /usr/include/glib-2.0/glib/gasyncqueue.h /usr/include/glib-2.0/glib/gatomic.h /usr/include/glib-2.0/glib/gbacktrace.h /usr/include/glib-2.0/glib/gbase64.h /usr/include/glib-2.0/glib/gbitlock.h /usr/include/glib-2.0/glib/gbookmarkfile.h /usr/include/glib-2.0/glib/gbytes.h /usr/include/glib-2.0/glib/gcharset.h /usr/include/glib-2.0/glib/gchecksum.h /usr/include/glib-2.0/glib/gconvert.h /usr/include/glib-2.0/glib/gdataset.h /usr/include/glib-2.0/glib/gdate.h /usr/include/glib-2.0/glib/gdatetime.h /usr/include/glib-2.0/glib/gdir.h /usr/include/glib-2.0/glib/genviron.h /usr/include/glib-2.0/glib/gerror.h /usr/include/glib-2.0/glib/gfileutils.h /usr/include/glib-2.0/glib/ggettext.h /usr/include/glib-2.0/glib/ghash.h /usr/include/glib-2.0/glib/ghmac.h /usr/include/glib-2.0/glib/ghook.h /usr/include/glib-2.0/glib/ghostutils.h /usr/include/glib-2.0/glib/giochannel.h /usr/include/glib-2.0/glib/gkeyfile.h /usr/include/glib-2.0/glib/glib-autocleanups.h /usr/include/glib-2.0/glib/glist.h /usr/include/glib-2.0/glib/gmacros.h /usr/include/glib-2.0/glib/gmain.h /usr/include/glib-2.0/glib/gmappedfile.h /usr/include/glib-2.0/glib/gmarkup.h /usr/include/glib-2.0/glib/gmem.h /usr/include/glib-2.0/glib/gmessages.h /usr/include/glib-2.0/glib/gnode.h /usr/include/glib-2.0/glib/goption.h /usr/include/glib-2.0/glib/gpattern.h /usr/include/glib-2.0/glib/gpoll.h /usr/include/glib-2.0/glib/gprimes.h /usr/include/glib-2.0/glib/gqsort.h /usr/include/glib-2.0/glib/gquark.h /usr/include/glib-2.0/glib/gqueue.h /usr/include/glib-2.0/glib/grand.h /usr/include/glib-2.0/glib/gregex.h /usr/include/glib-2.0/glib/gscanner.h /usr/include/glib-2.0/glib/gsequence.h /usr/include/glib-2.0/glib/gshell.h /usr/include/glib-2.0/glib/gslice.h /usr/include/glib-2.0/glib/gslist.h /usr/include/glib-2.0/glib/gspawn.h /usr/include/glib-2.0/glib/gstrfuncs.h /usr/include/glib-2.0/glib/gstring.h /usr/include/glib-2.0/glib/gstringchunk.h /usr/include/glib-2.0/glib/gtestutils.h /usr/include/glib-2.0/glib/gthread.h /usr/include/glib-2.0/glib/gthreadpool.h /usr/include/glib-2.0/glib/gtimer.h /usr/include/glib-2.0/glib/gtimezone.h /usr/include/glib-2.0/glib/gtrashstack.h /usr/include/glib-2.0/glib/gtree.h /usr/include/glib-2.0/glib/gtypes.h /usr/include/glib-2.0/glib/gunicode.h /usr/include/glib-2.0/glib/gurifuncs.h /usr/include/glib-2.0/glib/gutils.h /usr/include/glib-2.0/glib/gvariant.h /usr/include/glib-2.0/glib/gvarianttype.h /usr/include/glib-2.0/glib/gversion.h /usr/include/glib-2.0/glib/gversionmacros.h /usr/include/glib-2.0/glib/gwin32.h /usr/include/glib-2.0/gobject/gbinding.h /usr/include/glib-2.0/gobject/gboxed.h /usr/include/glib-2.0/gobject/gclosure.h /usr/include/glib-2.0/gobject/genums.h /usr/include/glib-2.0/gobject/glib-types.h /usr/include/glib-2.0/gobject/gmarshal.h /usr/include/glib-2.0/gobject/gobject-autocleanups.h /usr/include/glib-2.0/gobject/gobject.h /usr/include/glib-2.0/gobject/gparam.h /usr/include/glib-2.0/gobject/gparamspecs.h /usr/include/glib-2.0/gobject/gsignal.h /usr/include/glib-2.0/gobject/gsourceclosure.h /usr/include/glib-2.0/gobject/gtype.h /usr/include/glib-2.0/gobject/gtypemodule.h /usr/include/glib-2.0/gobject/gtypeplugin.h /usr/include/glib-2.0/gobject/gvalue.h /usr/include/glib-2.0/gobject/gvaluearray.h /usr/include/glib-2.0/gobject/gvaluetypes.h /usr/include/gstreamer-1.0/gst/glib-compat.h /usr/include/gstreamer-1.0/gst/gst.h /usr/include/gstreamer-1.0/gst/gstallocator.h /usr/include/gstreamer-1.0/gst/gstatomicqueue.h /usr/include/gstreamer-1.0/gst/gstbin.h /usr/include/gstreamer-1.0/gst/gstbuffer.h /usr/include/gstreamer-1.0/gst/gstbufferlist.h /usr/include/gstreamer-1.0/gst/gstbufferpool.h /usr/include/gstreamer-1.0/gst/gstbus.h /usr/include/gstreamer-1.0/gst/gstcaps.h /usr/include/gstreamer-1.0/gst/gstcapsfeatures.h /usr/include/gstreamer-1.0/gst/gstchildproxy.h /usr/include/gstreamer-1.0/gst/gstclock.h /usr/include/gstreamer-1.0/gst/gstcompat.h /usr/include/gstreamer-1.0/gst/gstcontext.h /usr/include/gstreamer-1.0/gst/gstcontrolbinding.h /usr/include/gstreamer-1.0/gst/gstcontrolsource.h /usr/include/gstreamer-1.0/gst/gstdatetime.h /usr/include/gstreamer-1.0/gst/gstdebugutils.h /usr/include/gstreamer-1.0/gst/gstdevice.h /usr/include/gstreamer-1.0/gst/gstdevicemonitor.h /usr/include/gstreamer-1.0/gst/gstdeviceprovider.h /usr/include/gstreamer-1.0/gst/gstdeviceproviderfactory.h /usr/include/gstreamer-1.0/gst/gstelement.h /usr/include/gstreamer-1.0/gst/gstelementfactory.h /usr/include/gstreamer-1.0/gst/gstelementmetadata.h /usr/include/gstreamer-1.0/gst/gstenumtypes.h /usr/include/gstreamer-1.0/gst/gsterror.h /usr/include/gstreamer-1.0/gst/gstevent.h /usr/include/gstreamer-1.0/gst/gstformat.h /usr/include/gstreamer-1.0/gst/gstghostpad.h /usr/include/gstreamer-1.0/gst/gstinfo.h /usr/include/gstreamer-1.0/gst/gstiterator.h /usr/include/gstreamer-1.0/gst/gstmacros.h /usr/include/gstreamer-1.0/gst/gstmemory.h /usr/include/gstreamer-1.0/gst/gstmessage.h /usr/include/gstreamer-1.0/gst/gstmeta.h /usr/include/gstreamer-1.0/gst/gstminiobject.h /usr/include/gstreamer-1.0/gst/gstobject.h /usr/include/gstreamer-1.0/gst/gstpad.h /usr/include/gstreamer-1.0/gst/gstpadtemplate.h /usr/include/gstreamer-1.0/gst/gstparamspecs.h /usr/include/gstreamer-1.0/gst/gstparse.h /usr/include/gstreamer-1.0/gst/gstpipeline.h /usr/include/gstreamer-1.0/gst/gstplugin.h /usr/include/gstreamer-1.0/gst/gstpluginfeature.h /usr/include/gstreamer-1.0/gst/gstpoll.h /usr/include/gstreamer-1.0/gst/gstpreset.h /usr/include/gstreamer-1.0/gst/gstprotection.h /usr/include/gstreamer-1.0/gst/gstquery.h /usr/include/gstreamer-1.0/gst/gstregistry.h /usr/include/gstreamer-1.0/gst/gstsample.h /usr/include/gstreamer-1.0/gst/gstsegment.h /usr/include/gstreamer-1.0/gst/gststructure.h /usr/include/gstreamer-1.0/gst/gstsystemclock.h /usr/include/gstreamer-1.0/gst/gsttaglist.h /usr/include/gstreamer-1.0/gst/gsttagsetter.h /usr/include/gstreamer-1.0/gst/gsttask.h /usr/include/gstreamer-1.0/gst/gsttaskpool.h /usr/include/gstreamer-1.0/gst/gsttoc.h /usr/include/gstreamer-1.0/gst/gsttocsetter.h /usr/include/gstreamer-1.0/gst/gsttypefind.h /usr/include/gstreamer-1.0/gst/gsttypefindfactory.h /usr/include/gstreamer-1.0/gst/gsturi.h /usr/include/gstreamer-1.0/gst/gstutils.h /usr/include/gstreamer-1.0/gst/gstvalue.h /usr/include/gstreamer-1.0/gst/gstversion.h /usr/include/gstreamer-1.0/gst/mpegts/gst-atsc-section.h /usr/include/gstreamer-1.0/gst/mpegts/gst-dvb-descriptor.h /usr/include/gstreamer-1.0/gst/mpegts/gst-dvb-section.h /usr/include/gstreamer-1.0/gst/mpegts/gst-scte-section.h /usr/include/gstreamer-1.0/gst/mpegts/gstmpegts-enumtypes.h /usr/include/gstreamer-1.0/gst/mpegts/gstmpegtsdescriptor.h /usr/include/gstreamer-1.0/gst/mpegts/gstmpegtssection.h /usr/include/gstreamer-1.0/gst/mpegts/mpegts.h /usr/lib/glib-2.0/include/glibconfig.h /usr/lib/gstreamer-1.0/include/gst/gstconfig.h CMakeFiles/mpegsttest.dir/flags.make
/usr/bin/cmake -E cmake_echo_color --switch= --green --progress-dir=/home/dev3lx/build/mpegts/CMakeFiles --progress-num=1 "Building C object CMakeFiles/mpegsttest.dir/mpegtstest.c.o"
[ 50%] Building C object CMakeFiles/mpegsttest.dir/mpegtstest.c.o
/usr/bin/cc   -I/home/dev3lx/build/mpegts -I/home/dev3lx/Development/mptestsrc/.. -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gio-unix-2.0 -I/usr/include/gstreamer-1.0 -I/usr/lib/gstreamer-1.0/include   -o CMakeFiles/mpegsttest.dir/mpegtstest.c.o   -c /home/dev3lx/Development/mptestsrc/mpegtstest.c
CMakeFiles/mpegsttest.dir/build.make:95: update target 'mpegsttest' due to: CMakeFiles/mpegsttest.dir/link.txt CMakeFiles/mpegsttest.dir/mpegtstest.c.o CMakeFiles/mpegsttest.dir/build.make /usr/lib64/libgstreamer-1.0.so
/usr/bin/cmake -E cmake_echo_color --switch= --green --bold --progress-dir=/home/dev3lx/build/mpegts/CMakeFiles --progress-num=2 "Linking C executable mpegsttest"
[100%] Linking C executable mpegsttest
/usr/bin/cmake -E cmake_link_script CMakeFiles/mpegsttest.dir/link.txt --verbose=
/usr/bin/ld: cannot find -lgstreamer-mpegts-1.0
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mpegsttest.dir/build.make:96: mpegsttest] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/mpegsttest.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

在网上搜索并尝试了一些在网上找到的不同的东西(比如这里)并查看 Github 代码后,我们不知道为什么或如何修复它。非常感谢任何建议或帮助。提前致谢。


解决方案 感谢 nega 的评论和解决方案,更改include_directories(${GSTREAMER-MPEGTS_INCLUDE_DIRS})include_directories(${GSTREAMER_MPEGTS_INCLUDE_DIRS})工作。

标签: clinuxcmakegstreamer

解决方案


根据您的cmake输出,我猜您正在使用FindGStreamer.cmake WebKit 的 cribbed版本。如果是这种情况,您要使用的变量是GSTREAMER_MPEGTS_INCLUDE_DIRS. 请注意变量名称中缺少连字符。

如果不是这种情况,message()请在使用变量之前使用一个简单的语句来在该cmake步骤中向您显示它的值。

在你的CMakeLists.txt

message("GMID: ${GSTREAMER_MPEGTS_INCLUDE_DIRS}")
include_directories(${GSTREAMER_MPEGTS_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} gstreamer-mpegts-1.0)

在你的外壳中:

$ cmake ../src |grep -i ^gmid
GMID: /usr/local/Cellar/libffi/3.3_2/include;/usr/local/Cellar/gst-plugins-bad/1.18.3/include/gstreamer-1.0;/usr/local/Cellar/gstreamer/1.18.3/include/gstreamer-1.0;/usr/local/Cellar/glib/2.66.7/include;/usr/local/Cellar/glib/2.66.7/include/glib-2.0;/usr/local/Cellar/glib/2.66.7/lib/glib-2.0/include;/usr/local/opt/gettext/include;/usr/local/Cellar/pcre/8.44/include

另一个简单的调试步骤是grep运行后去缓存cmake

$ grep -i ^gstream CMakeCache.txt
GSTREAMER_APP_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstapp-1.0.dylib
GSTREAMER_AUDIO_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstaudio-1.0.dylib
GSTREAMER_BASE_LIBRARIES:FILEPATH=/usr/local/Cellar/gstreamer/1.18.3/lib/libgstbase-1.0.dylib
GSTREAMER_CODECPARSERS_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-bad/1.18.3/lib/libgstcodecparsers-1.0.dylib
GSTREAMER_FFT_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstfft-1.0.dylib
GSTREAMER_FULL_LIBRARIES:FILEPATH=GSTREAMER_FULL_LIBRARIES-NOTFOUND
GSTREAMER_GL_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstgl-1.0.dylib
GSTREAMER_LIBRARIES:FILEPATH=/usr/local/Cellar/gstreamer/1.18.3/lib/libgstreamer-1.0.dylib
GSTREAMER_MPEGTS_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-bad/1.18.3/lib/libgstmpegts-1.0.dylib
GSTREAMER_PBUTILS_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstpbutils-1.0.dylib
GSTREAMER_TAG_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgsttag-1.0.dylib
GSTREAMER_VIDEO_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstvideo-1.0.dylib

推荐阅读