简体   繁体   English

如何在 C 中编译一个简单的 MLT 示例?

[英]How to compile a simple MLT example in C?

I am trying to compile an example code from the MLT Framework website that shows how consumer/producer work.我正在尝试从MLT Framework 网站编译一个示例代码,该代码显示消费者/生产者的工作方式。 The code is as follows:代码如下:

#include <stdio.h>
#include <unistd.h>
#include <framework/mlt.h>

int main( int argc, char *argv[] )
{
    // Initialise the factory
    if ( mlt_factory_init( NULL ) == 0 )
    {
        // Create the default consumer
        mlt_consumer hello = mlt_factory_consumer( NULL, NULL );

        // Create via the default producer
        mlt_producer world = mlt_factory_producer( NULL, argv[ 1 ] );

        // Connect the producer to the consumer
        mlt_consumer_connect( hello, mlt_producer_service( world ) );

        // Start the consumer
        mlt_consumer_start( hello );

        // Wait for the consumer to terminate
        while( !mlt_consumer_is_stopped( hello ) )
            sleep( 1 );

        // Close the consumer
        mlt_consumer_close( hello );

        // Close the producer
        mlt_producer_close( world );

        // Close the factory
        mlt_factory_close( );
    }
    else
    {
        // Report an error during initialisation
        fprintf( stderr, "Unable to locate factory modules\n" );
    }

    // End of program
    return 0;
}

The file name is player.c.文件名为 player.c。
I cannot use make to compile it with make player as it does not find include files.我无法使用 make 与make player一起编译它,因为它找不到包含文件。

I am using the following command to compile with gcc:我正在使用以下命令与 gcc 一起编译:

 # gcc -I /usr/include/mlt -l libmltcore -o player player.c 
/usr/bin/ld: cannot find -llibmltcore
collect2: error: ld returned 1 exit status

As you can see the linker cannot find the mlt library.如您所见,linker 找不到 mlt 库。 OS is Fedora 32 and I have installed mlt-devel and I am sure I have the following libs in /usr/lib64/mlt:操作系统是 Fedora 32,我已经安装了 mlt-devel,我确信我在 /usr/lib64/mlt 中有以下库:

libmltavformat.so  libmltlinsys.so      libmltqt.so         libmltvidstab.so
libmltcore.so      libmltmotion_est.so  libmltresample.so   libmltvmfx.so
libmltdecklink.so  libmltnormalize.so   libmltrtaudio.so    libmltvorbis.so
libmltfrei0r.so    libmltoldfilm.so     libmltsdl2.so       libmltxml.so
libmltgtk2.so      libmltopengl.so      libmltsdl.so
libmltjackrack.so  libmltplusgpl.so     libmltsox.so
libmltkdenlive.so  libmltplus.so        libmltvideostab.so

What am I doing wrong?我究竟做错了什么?

My second question is why does GCC not find the include files and libraries in the first place so that I have to specify them manually?我的第二个问题是为什么 GCC 首先找不到包含文件和库,所以我必须手动指定它们?

regarding:关于:

gcc -I /usr/include/mlt -l libmltcore -o player player.c`

The linker handles things in the order they are listed on the command. linker 按照命令中列出的顺序处理事物。 So when the linker encounters -l libmitcore there are no unresolved external references so nothing is included so in the end the link step will fail.因此,当 linker 遇到-l libmitcore时,没有未解析的外部引用,因此没有包含任何内容,因此最后链接步骤将失败。 Suggest:建议:

gcc player.c -o player -I /usr/include/mlt -l libmltcore

regarding:关于:

/usr/bin/ld: cannot find -llibmltcore

if the libmltcore is not on one of the 'standard' library directories, it will not be found, UNLESS the command also includes the library path.如果libmltcore不在“标准”库目录之一上,则不会找到它,除非该命令还包含库路径。 Suggest including the following parameter, before the library name:建议在库名称之前包含以下参数:

-L /usr/lib64/mlt

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

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