在Windows上使用cmake编译gstreamer应用程序



我正在尝试使用cmake在windows下使用gstreamer库。

这是我的简单测试代码:

#include <gst/gst.h>
int main (void)
{
    gst_init (NULL, NULL);
    return 0;
}

我从这里得到了lib("gstreamer-1.0-devel-x86-1.6.1.msi"):http://gstreamer.freedesktop.org/data/pkg/windows/1.6.1/

并尝试使用以下CMakeList.txt编译程序:

cmake_minimum_required(VERSION 2.8.12)
project(test_g)
SET(CMAKE_CXX_WARNING_LEVEL 4)
if (MSVC)
        add_definitions("/W4")
else()
        add_definitions("-Wall -Wextra")
endif ()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
file(
        GLOB_RECURSE
        source_files
        ./*
)
file(
        GLOB_RECURSE
        gst_files
        ${CMAKE_CURRENT_SOURCE_DIR}/deps/lib/*.a
        ${CMAKE_CURRENT_SOURCE_DIR}/deps/lib/*.lib
)
add_executable(
        test_g
        ${source_files}
)
  set(GSTREAMER_INCLUDE_DIRS "./deps/include/gstreamer-1.0" "./deps/include/glib-2.0" "./deps/lib/glib-2.0/include" "./deps/lib/gstreamer-1.0/include")
  if (WIN32)
   set(GSTREAMER_LIBRARIES ${gst_files})
  else()
    message(FATAL_ERROR "Gstreamer not found")
  endif()
include_directories(${GSTREAMER_INCLUDE_DIRS})
target_link_libraries (test_g ${GSTREAMER_LIBRARIES})

我希望避免使用pkgconfig,因为我的目标是使其易于编译。

不幸的是,这不起作用:

[ 33%] Linking CXX executable test_g.exe
C:/Users/toto/Documents/GitHub/test_gst/deps/lib/libgstreamer-1.0.a(libgstreamer_1.0_la-gst.o): In function `init_post':
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gst.c:719: undefined reference to `_imp__glib_micro_version'
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gst.c:719: undefined reference to `_imp__glib_minor_version'
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gst.c:719: undefined reference to `_imp__glib_major_version'
C:/Users/toto/Documents/GitHub/test_gst/deps/lib/libgstreamer-1.0.a(libgstreamer_1.0_la-gstinfo.o): In function `parse_debug_level':
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gstinfo.c:1771: undefined reference to `_imp__g_ascii_table'
C:/Users/toto/Documents/GitHub/test_gst/deps/lib/libgstreamer-1.0.a(libgstreamer_1.0_la-gstinfo.o): In function `gst_path_basename':
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gstinfo.c:467: undefined reference to `_imp__g_ascii_table'
C:/Users/toto/Documents/GitHub/test_gst/deps/lib/libgstreamer-1.0.a(libgstreamer_1.0_la-gstinfo.o): In function `gst_info_dump_mem_line':
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gstinfo.c:1931: undefined reference to `_imp__g_ascii_table'
C:/Users/toto/Documents/GitHub/test_gst/deps/lib/libgstreamer-1.0.a(libgstreamer_1.0_la-gststructure.o): In function `gst_structure_parse_simple_string':
C:MinGWmsys1.0homeJancerberosourceswindows_x86gstreamer-1.0-1.6gst/gststructure.c:2221: undefined reference to `_imp__g_ascii_table'
C:/Users/toto/Documents/GitHub/test_gst/deps/lib/libgstreamer-1.0.a(libgstreamer_1.0_la-gststructure.o): In function `gst_structure_validate_name':
... Many other errors ...

我的问题如下:

  • 我应该同时使用.lib和.a文件吗?

  • 为什么它不编译?libglib-2.0.dll.a文件在lib目录中,所以我不确定链接过程中的问题是什么。。。

谢谢!


好的,我发现了问题所在。我只需要获取*dll.a文件,所以现在的代码是:

file(
        GLOB_RECURSE
        gst_files
        ${CMAKE_CURRENT_SOURCE_DIR}/deps/lib/*dll.a
)

我想我们可以用适当的方式来做,所以如果有人有更好的想法,我会感兴趣的。

最新更新