无法链接到FFmpeg库 [英] Unable to link against FFmpeg libaries
问题描述
#include< libavutil / log.h> ;
int main(int argc,char * argv [])
{
:: av_log_set_flags(AV_LOG_SKIP_REPEATED);
return 0;
}
我的发行版是Debian GNU / Linux 8(jessie)。 FFmpeg由我自己构建,configure命令是...
$ ./configure --prefix = / usr /本地--disable-static --enable-shared \
> --extra-ldflags =' - Wl,-rpath = / usr / local / lib'
链接错误如下。
$ g ++ foo.cpp -D__STDC_CONSTANT_MACROS -Wall \
> -Wl,-rpath = / usr / local / lib \
> $(pkg-config --cflags --libs libavutil)
/tmp/ccKzgEFb.o:在函数`main'中:
foo.cpp :( .text + 0x17):未定义的引用`av_log_set_flags (int)'
collect2:错误:ld返回1退出状态
pkg-config
是...
$ pkg-config - cflags --libs libavutil
-I / usr / local / include -L / usr / local / lib -lavutil
objdump
显示共享对象libavutil.so里面有 av_log_set_flogs
。
$ objdump --dynamic-syms /usr/local/lib/libavutil.so | grep'av_log_set_flags'
000260f0 g DF .text 0000000a LIBAVUTIL_54 av_log_set_flags
请注意, code> g ++ 命令用于构建上述应用程序具有链接器选项 -Wl,-rpath = / usr / local / lib
虽然它仍然不起作用。另外,如果调用发行版提供的其他版本,我已经尝试使用 inotifywait
监视。他们不是,在执行 g ++
期间打开的那个是/usr/local/lib/libavutil.so。
总结:
-
/usr/local/lib/libavutil.so确实有符号。
-
-rpath
用于强制与共享库链接。 -
为什么链接时错误? T_T
任何建议或信息都将非常感激!谢谢!
REEDIT: ffplay
工作正常, ldd
显示它使用/usr/local/lib/libavutil.so。所以图书馆似乎没有破坏,问题就是如何建立自己的代码来使用这些库。
我也很困惑了一会儿。我设法google了这个: http://soledadpenades.com/2009/ 11/24 / links-with-ffmpegs-libav /
结果是 FFMPEG
don'不要使头文件 C ++
知道。
这是修复程序:
externC
{
#include }
int main(int argc,char * argv [])
{
:: av_log_set_flags(AV_LOG_SKIP_REPEATED);
return 0;
}
您需要将所有 ffmpeg
header包含 externC
链接。
I tried to build this, but always got link-time error.
#include <libavutil/log.h>
int main(int argc, char *argv[])
{
::av_log_set_flags(AV_LOG_SKIP_REPEATED);
return 0;
}
My distro is Debian GNU/Linux 8 (jessie). The FFmpeg was built by myself, and the configure command was...
$ ./configure --prefix=/usr/local --disable-static --enable-shared \
> --extra-ldflags='-Wl,-rpath=/usr/local/lib'
The link-error is as follows.
$ g++ foo.cpp -D__STDC_CONSTANT_MACROS -Wall \
> -Wl,-rpath=/usr/local/lib \
> $(pkg-config --cflags --libs libavutil)
/tmp/ccKzgEFb.o: In function `main':
foo.cpp:(.text+0x17): undefined reference to `av_log_set_flags(int)'
collect2: error: ld returned 1 exit status
where the output of pkg-config
is...
$ pkg-config --cflags --libs libavutil
-I/usr/local/include -L/usr/local/lib -lavutil
The objdump
shows that the shared object libavutil.so does have av_log_set_flogs
inside.
$ objdump --dynamic-syms /usr/local/lib/libavutil.so | grep 'av_log_set_flags'
000260f0 g DF .text 0000000a LIBAVUTIL_54 av_log_set_flags
Please note that the g++
command used to build the above application had a linker option -Wl,-rpath=/usr/local/lib
, though it still doesn't work. Also, I've tried to monitor with inotifywait
if the other version provided by the distro were called. They were not, and the one being opened during execution of g++
was /usr/local/lib/libavutil.so.
Summary:
/usr/local/lib/libavutil.so does have the symbol.
-rpath
was used to force to link against the shared library.Why link-time error? T_T
Any suggestion or information would be highly appreciated! Thanks!
REEDIT: ffplay
works fine and ldd
shows it use /usr/local/lib/libavutil.so. So, the libraries seems not broken, and the problem becomes how to build my own codes to use the libraries.
This had me baffled too for a while. I managed to google this: http://soledadpenades.com/2009/11/24/linking-with-ffmpegs-libav/
It turns out FFMPEG
don't make their header files C++
aware.
Here is the fix:
extern "C"
{
#include <libavutil/log.h>
}
int main(int argc, char *argv[])
{
::av_log_set_flags(AV_LOG_SKIP_REPEATED);
return 0;
}
You need to wrap all ffmpeg
header includes with extern "C"
linkage.
这篇关于无法链接到FFmpeg库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!