提问者:小点点

Libav链接错误:未定义引用


我的问题是:

  • 我从源代码(1.2版)构建了ffmpeg,libav*库位于/usr/local/lib中,它们是静态的
  • 我正在编译一个ns3(www.nsnam.org)模块,因此我对链接器的唯一控制是通过env变量linkflags
  • 在源代码中,头位于“extern c”块中,因此这不是常见的G++名称混乱
  • 我设置了linkflags=“-I/usr/local/include/libavformat-i/usr/local/include/libavcodec-i/usr/local/include/libavutil-l/usr/local/lib-lavformat-lavcodec-lavutil”,链接器似乎找不到我调用的任何libav*函数(我得到很多“未定义的引用”,然后是“collect2:error:ld returned status 1”

有人能帮我吗?谢谢。。。

编辑:下面是一些未定义的引用消息:

    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_guess_format'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_read_frame'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_write_header'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_interleaved_write_frame'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_find_stream_info'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_register_all'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_init_packet'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avformat_alloc_context'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `av_dump_format'
    ./libns3.14.1-qoe-monitor-debug.so: undefined reference to `avio_close'

Edit2:下面是我在“构建失败”之后得到的消息:

-> task in 'scratch-simulator' failed (exit status 1): 
{task 53952272: cxxprogram scratch-simulator.cc.1.o -> scratch-simulator}
['/usr/bin/g++', '-I/usr/local/include/libavcodec', '-I/usr/local/include/libavformat/',
 '-I/usr/local/include/libavutil/', '-L/usr/local/lib', '-I/usr/local
/include/libavcodec', '-I/usr/local/include/libavformat/', '-I/usr/local/include
/libavutil/', '-L/usr/local/lib', '-pthread', '-pthread', '-Wl,-z,relro', 
'scratch/scratch-simulator.cc.1.o', '-o', '/home/fede/Thesis/ns-allinone-3.14.1
/ns-3.14.1/build/scratch/scratch-simulator', '-Wl,-Bstatic', '-Wl,-Bdynamic', 
'-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',
 '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.',
 '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', 
'-L.', '-L.', '-L.', '-L.', '-L.', '-L/usr/lib', '-lns3.14.1-test-debug', '-lns3.14.1-
csma-layout-debug', '-lns3.14.1-point-to-point-layout-debug', '-lns3.14.1-netanim-
debug', '-lns3.14.1-lte-debug', '-lns3.14.1-spectrum-debug', '-lns3.14.1-antenna-
debug', '-lns3.14.1-aodv-debug', '-lns3.14.1-dsdv-debug', '-lns3.14.1-dsr-debug', 
'-lns3.14.1-mesh-debug', '-lns3.14.1-olsr-debug', '-lns3.14.1-csma-debug', '-lns3.14.1-
wimax-debug', '-lns3.14.1-applications-debug', '-lns3.14.1-virtual-net-device-debug', 
'-lns3.14.1-uan-debug', '-lns3.14.1-energy-debug', '-lns3.14.1-flow-monitor-debug', 
'-lns3.14.1-nix-vector-routing-debug', '-lns3.14.1-tap-bridge-debug', '-lns3.14.1-
visualizer-debug', '-lns3.14.1-internet-debug', '-lns3.14.1-bridge-debug', '-lns3.14.1-
point-to-point-debug', '-lns3.14.1-mpi-debug', '-lns3.14.1-wifi-debug', '-lns3.14.1-
buildings-debug', '-lns3.14.1-propagation-debug', '-lns3.14.1-mobility-debug', 
'-lns3.14.1-config-store-debug', '-lns3.14.1-tools-debug', '-lns3.14.1-stats-debug',
 '-lns3.14.1-emu-debug', '-lns3.14.1-topology-read-debug', '-lns3.14.1-network-debug', 
'-lns3.14.1-qoe-monitor-debug', '-lns3.14.1-core-debug', '-lrt', '-lgsl', 
'-lgslcblas', '-lm', '-ldl', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0', 
'-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo', 
'-lpango-1.0', '-lfreetype', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lxml2', 
'-lpython2.7']

共3个答案

匿名用户

库是C.当编译为C++时,库头不包括外部“C”。在您的C++源代码中执行此操作:

extern "C" { 
#include <libavcodec/avcodec.h> 
#include <libavformat/avformat.h>
}

或者,更一般地说,对于混合的C和C++源代码:

#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h> 
#include <libavformat/avformat.h>
#ifdef __cplusplus 
}
#endif

你应该会没事的。

匿名用户

我在av_find_stream_info上遇到了这个问题,问题是不推荐使用这个函数。问题是我有两个ffmpeg安装在盒子上,它是读取头从一个安装和使用库从不同的安装。

删除系统默认库后,问题得到解决。

更新:对于Ubuntu,我做了以下工作:

$ sudo dpkg -r libavcodec53
$ sudo dpkg -r libavformat53
$ sudo dpkg -r libavutil51
$ sudo dpkg -r libswscale2

匿名用户

只是在我自己的搜索中遇到了这个问题。

在waf构建系统中,您应该使用STLIB和STLIBPATH来表示静态库名和路径,而不是使用linkflags。请注意,您应该将STLIB设置为要使用的静态库名称列表,不带前缀或扩展名。

在wscript文件中,添加

conf.env.append_value("STLIBPATH", ["/usr/local/lib"])
conf.env.append_value("STLIB", ["av*,av**"])