简体   繁体   English

我如何创建一个使用开源C项目的C ++控制台应用程序

[英]How can I create a c++ console application which makes use of an open source c project

I've been playing around with a compiled version of https://github.com/FFmpeg/FFmpeg . 我一直在玩https://github.com/FFmpeg/FFmpeg的编译版本。 But it has some problems, during the closing of an opened stream using avio_close (it takes a really long time to close it). 但是,在使用avio_close关闭打开的流期间,它存在一些问题(关闭它需要很长时间)。

I've been trying to understand what could go wrong by reading through the implementation, but couldn't find anything. 我一直在尝试通过阅读实现来理解可能出了什么问题,但却找不到任何东西。

What I would like to do, is to actually have a C++ console application which uses the c files and to debug them while running the code(using breakpoints and so on). 我想做的是实际上有一个使用c文件的C ++控制台应用程序,并在运行代码时调试它们(使用断点等)。

Unfortunately I cannot find any information on how to set it up. 不幸的是,我找不到有关如何进行设置的任何信息。 Simply copying the files in a new console application is not enough. 仅在新的控制台应用程序中复制文件是不够的。

Thanks in advance for any suggestions. 在此先感谢您的任何建议。

Edit: I can already see a closing vote. 编辑:我已经可以看到结束投票。 If this question is not appropriate for this website, I will delete it. 如果此问题不适合该网站,我将其删除。 But please point me in the right direction of where to post it.Although it is quite a general question, I believe that it is clear and enough information has been provided. 但是请指出正确的发布方向,尽管这是一个普遍的问题,但我认为它很清楚并且已经提供了足够的信息。

Edit2: Yes, I was a bit unclear about what I'm using. Edit2:是的,我不清楚自己在使用什么。

I'm using Visual Studio Community 2017 on Windows 10 for creating the C++ console application. 我正在Windows 10上使用Visual Studio Community 2017创建C ++控制台应用程序。

Edit3: 编辑3:

Steps that I've taken into using the source files into my console application which was using the DLLs. 我在使用DLL的控制台应用程序中使用源文件所采取的步骤。

  1. Copy all of the contents of the FFmpeg-master to my console application 将FFmpeg-master的所有内容复制到我的控制台应用程序
  2. Include all of them in the c++ console application project 将所有这些都包括在c ++控制台应用程序项目中
  3. Run a build - takes forever and has infinite build errors( > 1000) - probably compiler related 运行构建-花费很长时间并且有无限的构建错误(> 1000)-可能与编译器相关

Edit4: 编辑4:

I have no actual errors with avio_close , it just takes too long to close the stream. 我没有avio_close实际错误,关闭流只是花费太长时间。 What I found out when playing around with the settings is that when the fifo_size parameter is set, closing the stream is a lot faster depending on how small the set value is. 我在进行这些设置时发现,设置了fifo_size参数后,关闭流的速度要快得多,具体取决于设置值的大小。 And it sort of makes sense since fifo_size is related to the packet size, but I haven't found out where in the code this size has an impact. 由于fifo_size与数据包大小有关,因此这fifo_size ,但我还没有发现此大小在代码中有影响。

fifo_size=units Set the UDP receiving circular buffer size, expressed as a number of packets with size of 188 bytes. fifo_size = units设置UDP接收循环缓冲区的大小,以188个字节的数据包数表示。 If not specified defaults to 7*4096. 如果未指定,则默认为7 * 4096。

Edit5: I still haven't found a way to compile the open source ffmpeg project into libs, dlls and pdbs. Edit5:我仍然没有找到一种将开源ffmpeg项目编译成libs,dll和pdbs的方法。 Am I the first one needing such files(seems unrealistic)? 我是第一个需要此类文件的人(似乎不现实)吗? The only tool capable of delivering those so far is vcpkg . 到目前为止,唯一能够提供这些功能的工具是vcpkg The only problem is that it compiles the 3.3.3 version and the latest is 4.0.2 . 唯一的问题是它可以编译3.3.3版本,而最新版本是4.0.2。

I tried to modify the vcpkg\\ports\\ffmpeg\\portfile.cmake file to include the latest version of ffmpeg, but it doesn't build it. 我试图修改vcpkg\\ports\\ffmpeg\\portfile.cmake文件以包括ffmpeg的最新版本,但它没有构建它。

Are there any other suggestions? 还有其他建议吗?

There are some tools and workflows that you need to be confortable with in order to debug an application from the source code using a debugger. 您需要使用一些工具和工作流程,才能使用调试器从源代码调试应用程序。

First you need to know how to build the application. 首先,您需要知道如何构建应用程序。 That is usually achieved by running: 通常可以通过运行以下命令来实现:

$ ./configure
$ make

Since you want to debug, you must set some compiler flags that will instruct the compiler to produce debugging information that will be used by the debugger to relate machine instructions to the relevant lines of source code. 由于要调试,因此必须设置一些编译器标志,这些标志将指示编译器生成调试信息,调试器将使用这些信息将机器指令与相关的源代码行相关联。 In the case of FFMpeg, you just need to change the configure commad to: 在FFmpeg的情况下,你只需要配置commad更改为:

$ ./configure --enable-debug

Please take a look at $ configure --help to see all the options, configure is extremely well documented in this project. 请看一下$ configure --help来查看所有选项, configure在该项目中有很好的记录。

After running make you will have an executable that has debugging information, then you need to learn how to use a debugger. 运行make之后,您将具有包含调试信息的可执行文件,然后您需要学习如何使用调试器。 The gdb debugger is the one most used, and is actually the backend of most GUI debuggers. gdb调试器是最常用的调试器,实际上是大多数GUI调试器的后端。 There are lots of informations and tutorials on how to use gdb, please do a google search for gdb tutorial and choose the one you find most comprehensible. 有关如何使用gdb的信息和教程很多,请在Google上搜索gdb tutorial然后选择最容易理解的gdb tutorial

The most relevant tasks you will need to learn are how to set up breakpoints, print variables and stack traces. 您将需要学习的最相关的任务是如何设置断点,打印变量和堆栈跟踪。

Debugging using a command line interface like plain gdb has some advantages, but even old school people must admit that GUI comes in handy. 使用诸如纯gdb之类的命令行界面进行调试具有一些优势,但是即使是老派人士也必须承认GUI派上了用场。 So, as a last advise, after you understand and is confortable with the gdb workflow, you can search for a GUI debugger or even a full IDE that will certainly make your life much easier. 因此,作为最后的建议,在您理解gdb工作流程并对其感到满意之后,您可以搜索GUI调试器甚至是完整的IDE,这无疑会使您的生活变得更加轻松。

I ended up using vcpkg . 我最终使用了vcpkg

As a guide for building this specific (as in no idea if it would work the same for others open source projects) package: 作为构建此特定程序包的指南(不知道它是否适用于其他开源项目)包:

1) Download vcpkg and go through the installation process described in the README file 1)下载vcpkg并按照README文件中的说明进行安装

2) Go to 2)前往

..\\vcpkg\\ports\\ffmpeg\\ .. \\ vcpkg \\ ports \\ ffmpeg \\

and edit the portfile.cmake file. 并编辑portfile.cmake文件。

By default vcpkg will build the 3.3.3 version of ffmpeg and it uses 默认情况下,vcpkg将构建ffmpeg的3.3.3版本,并使用

vcpkg_download_distfile(ARCHIVE
URLS "http://ffmpeg.org/releases/ffmpeg-3.3.3.tar.bz2"
FILENAME "ffmpeg-3.3.3.tar.bz2"
SHA512 1cc63bf73356f4e618c0d3572a216bdf5689f10deff56b4262f6d740b0bee5a4b3eac234f45fca3d4d2da77903a507b4fba725b76d2d2070f31b6dae9e7a2dab
)

Change it to 更改为

vcpkg_download_distfile(ARCHIVE
    URLS "http://ffmpeg.org/releases/ffmpeg-4.0.2.tar.bz2"
    FILENAME "ffmpeg-4.0.2.tar.bz2"
    SHA512 92a3bedcd070df72b26dbe3ebf4a3faea0a02289fbefdb6a6c73d65801cf60a7e11cd832d29ab46b7749a1ffd0a31505cf75bb46bd01ea06423b454ca04e9b7b
)

This will download the latest ffmpeg version. 这将下载最新的ffmpeg版本。 In order for the build to work you also have to comment these lines: 为了使构建正常工作,您还必须注释以下行:

if("ffserver" IN_LIST FEATURES)
    set(OPTIONS "${OPTIONS} --enable-ffserver")
else()
    set(OPTIONS "${OPTIONS} --disable-ffserver")
endif()

I assume that since version 3.3.3 this option was removed/disabled and it doesn't work anymore. 我认为自版本3.3.3起,此选项已被删除/禁用,并且不再起作用。

3) Run(it will take a while) 3)运行(需要一段时间)

.\\vcpkg install ffmpeg 。\\ vcpkg安装ffmpeg

You should now have a 4.0.2 debug and release version of FFMPEG with DLLs, PDBs, libs and includes folders. 您现在应该有了FFMPEG的4.0.2调试和发行版本,其中包含DLL,PDB,lib和包含文件夹。

Not entirely sure if this process was correct, but my project is working fine and I'm now able to debug it. 不能完全确定此过程是否正确,但是我的项目运行正常,现在可以对其进行调试。

You can use vcpkg, open source packager, from github to build many open source projects including ffmpeg without any hassle. 您可以使用来自github的开源打包程序vcpkg来构建许多开源项目,包括ffmpeg,而不会遇到任何麻烦。 vcpkg has recently given support for non-windows platforms also, check it out. vcpkg最近也提供了对非Windows平台的支持,请查看。

A single one liner command on Powershell prompt .\\vcpkg install ffmpeg ,is all that is needed. 仅需要在Powershell提示符下输入一个衬板命令即可.\\vcpkg install ffmpeg As usual the vs console project could be subjected for debugging also. 与往常一样,vs控制台项目也可以进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM