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

标签 c++ c windows cmake gstreamer

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

这是我的简单测试代码:

#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:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/gst.c:719: undefined reference to `_imp__glib_micro_version'
C:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/gst.c:719: undefined reference to `_imp__glib_minor_version'
C:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/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:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/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:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/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:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/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:\MinGW\msys\1.0\home\Jan\cerbero\sources\windows_x86\gstreamer-1.0-1.6\gst/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
)

我想我们可以以正确的方式做到这一点,所以如果有人有更好的想法,我会很感兴趣。

关于c++ - 在 Windows 上使用 cmake 编译 gstreamer 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34318978/

相关文章:

c++ - 重载 make_heap?

c++ - 使用 atof 将字符串转换为 float 在末尾产生非常小的十进制数

c - netbsd 版本的 openssh 支持 "diffie-hellman-group-exchange-sha256",但不支持 Mac 的 SHA256

C Windows 缓冲区大小

c - 监 Windows 口的创建(HWND)

C++ 是否有另一种方法来首先访问成员和第二个访问成员,而不是对 std::vector <std::pair <int, int>> 使用范围 for 循环?

c++ - 从txt文件C++读取浮点错误值

C数组衰减消歧

c - "malloc"在 C/MPI 中起什么作用?

windows - 用于检查域中计算机名称的简单批处理脚本