Gcc C程序找不到头文件中包含的函数
我制作了这样的程序Gcc C程序找不到头文件中包含的函数,gcc,ffmpeg,header-files,undefined-reference,Gcc,Ffmpeg,Header Files,Undefined Reference,我制作了这样的程序 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include "libavformat/avformat.h" 5 6 int main (int argc, char* argv[]){ 7 av_register_all(); 8 return 0; 9 } 然后我使用gcc
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "libavformat/avformat.h"
5
6 int main (int argc, char* argv[]){
7 av_register_all();
8 return 0;
9 }
然后我使用gcc getDuration.c
运行,但我显示的消息如下所示
root@ubuntu:/home/juneyoungoh/getDuration# gcc getDuration.c
/tmp/ccwjonqH.o: In function `main':
getDuration.c:(.text+0x10): undefined reference to `av_register_all'
collect2: ld returned 1 exit status
apt-get install libavformat-dev
坦率地说,我不知道这是怎么回事
谢谢你的回答
===========================================编辑#1===========================
当我“ls/usr/local/lib”时,我得到了这个
root@ubuntu:/home/juneyoungoh/getDuration# ls /usr/local/lib/
libavcodec.a libavutil.a libopus.la libvpx.a python2.7
libavdevice.a libfdk-aac.a libpostproc.a libx264.a
libavfilter.a libfdk-aac.la libswresample.a libyasm.a
libavformat.a libopus.a libswscale.a pkgconfig
您可以在最后一行的第一行看到libavformat.a
所以,如果我像你建议的那样指挥,我会在下面
/root/ffmpeg/libavformat/vqf.c:244: undefined reference to `av_free_packet'
/usr/local/lib//libavformat.a(vqf.o): In function `add_metadata':
/root/ffmpeg/libavformat/vqf.c:58: undefined reference to `av_malloc'
/root/ffmpeg/libavformat/vqf.c:64: undefined reference to `av_dict_set'
/usr/local/lib//libavformat.a(vqf.o): In function `vqf_read_header':
/root/ffmpeg/libavformat/vqf.c:148: undefined reference to `av_dict_set'
/root/ffmpeg/libavformat/vqf.c:208: undefined reference to `av_log'
/root/ffmpeg/libavformat/vqf.c:216: undefined reference to `av_malloc'
/root/ffmpeg/libavformat/vqf.c:170: undefined reference to `av_log'
/root/ffmpeg/libavformat/vqf.c:121: undefined reference to `av_log'
/root/ffmpeg/libavformat/vqf.c:184: undefined reference to `av_log'
/root/ffmpeg/libavformat/vqf.c:136: undefined reference to `av_log'
/usr/local/lib//libavformat.a(wavenc.o): In function `wav_write_trailer':
/root/ffmpeg/libavformat/wavenc.c:210: undefined reference to `av_rescale'
/usr/local/lib//libavformat.a(wavenc.o): In function `wav_write_packet':
/root/ffmpeg/libavformat/wavenc.c:181: undefined reference to `av_log'
它太长了,所以我只发布了其中的一小部分
我想libavformat的所有链接都被破坏了,但我不知道
我可以做些什么来修复该链接
我已经安装了他们的官方链接说
您有一个链接错误;不是编译错误。您需要使用-l选项指定库文件。我认为应该是:
gcc getDuration.c -lavformat
如果不起作用,请将libavformat的位置指定为
gcc -L/usr/local/lib getDuration.c -lavformat
我发现我的代码有什么问题(确切地说,不是代码,而是环境) 要执行该代码,我需要一个名为“libavformat dev”的额外库 在我的例子中,由于我是Ubuntu 12.04的用户,我命令如下
root@ubuntu:/home/juneyoungoh/getDuration# gcc getDuration.c
/tmp/ccwjonqH.o: In function `main':
getDuration.c:(.text+0x10): undefined reference to `av_register_all'
collect2: ld returned 1 exit status
apt-get install libavformat-dev
我真是太遗憾了:(我假设系统可以找到头文件,因为如果没有,它会弹出消息“没有这样的文件或目录”,我错了吗?头文件不是库。包括头文件在内的头文件提供了函数声明,但您需要为链接器指定一个库来获得定义。@williampersell在这种情况下,库名称是“avformat”,头文件是“avformat.h”。对吗?谢谢。我尝试过这种方式,但我得到了其他未定义的函数消息。如果您愿意,我可以发布这些消息。是的,请发布您收到的消息。同时检查您是否在
/usr/local/lib
中拥有库libavformat.a
,