How to compile a simple MLT example in C?

182 views Asked by At

I am trying to compile an example code from the MLT Framework website that shows how consumer/producer work. 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.
I cannot use make to compile it with make player as it does not find include files.

I am using the following command to compile with 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. OS is Fedora 32 and I have installed mlt-devel and I am sure I have the following libs in /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?

1

There are 1 answers

1
user3629249 On

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. 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. 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. Suggest including the following parameter, before the library name:

-L /usr/lib64/mlt