如何用C编写一个简单的MLT示例?
我试图从中编译一个示例代码,展示消费者/生产者是如何工作的。代码如下:如何用C编写一个简单的MLT示例?,c,mlt,C,Mlt,我试图从中编译一个示例代码,展示消费者/生产者是如何工作的。代码如下: #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 ) { // Crea
#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;
}
如您所见,链接器找不到mlt库。OS是Fedora 32,我已经安装了mlt-devel,我确信在/usr/lib64/mlt中有以下libs:
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首先找不到包含文件和库,因此我必须手动指定它们?关于:
gcc -I /usr/include/mlt -l libmltcore -o player player.c`
/usr/bin/ld: cannot find -llibmltcore
链接器按照命令中列出的顺序处理对象。因此,当链接器遇到-l libmitcore
时,没有未解析的外部引用,因此不包含任何内容,因此最终链接步骤将失败。建议:
gcc player.c -o player -I /usr/include/mlt -l libmltcore
关于:
gcc -I /usr/include/mlt -l libmltcore -o player player.c`
/usr/bin/ld: cannot find -llibmltcore
如果libmltcore
不在其中一个“标准”库目录上,则将找不到它,除非该命令还包括库路径。建议在库名称之前包含以下参数:
-L /usr/lib64/mlt
“为什么GCC找不到包含文件”-它找到了;否则你就不会进入链接阶段。您是否尝试过
gcc-I/usr/include/mlt-L/usr/lib64/mlt-L libmltcore-o player.c
?没有,但lib目录中没有名为mlt的文件。这行吗?你的帖子字面意思是“我确信我在/usr/lib64/mlt
中有以下lib”,而现在你突然没有这些文件了?对不起,我不知道我代表的是目录。我正在查找具有该名称的特定文件。您的命令给出了以下输出:/usr/bin/ld:not find-llibmltcore collect2:error:ld返回了1个退出状态谢谢。实际上,gcc-player.c-o-player-I/usr/include/mlt-l mlt
工作正常。令人惊讶的是,我的lib路径中没有mlt.so,而是以libmlt开头的其他lib名称,例如libmltcore.so、libmltqt.so等等