首页 > 解决方案 > 如何在 C 中编译一个简单的 MLT 示例?

问题描述

我正在尝试从MLT Framework 网站编译一个示例代码,该代码显示消费者/生产者的工作方式。代码如下:

#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;
}

文件名为 player.c。
我不能使用 make 来编译它,make player因为它找不到包含文件。

我正在使用以下命令使用 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

如您所见,链接器找不到 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

我究竟做错了什么?

我的第二个问题是为什么 GCC 首先找不到包含文件和库,所以我必须手动指定它们?

标签: cmlt

解决方案


关于:

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

链接器按照命令中列出的顺序处理事物。因此,当链接器遇到-l libmitcore没有未解析的外部引用时,因此没有包含任何内容,因此最后链接步骤将失败。建议:

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

关于:

/usr/bin/ld: cannot find -llibmltcore

如果libmltcore不在“标准”库目录之一上,则不会找到它,除非该命令还包括库路径。建议在库名称之前包含以下参数:

-L /usr/lib64/mlt

推荐阅读