GCC:未定义引用 [英] gcc: undefined reference to
问题描述
我想编译这个。
program.c
的#include< libav codeC / AV codec.h>诠释主(){
INT I = avpicture_get_size(AV_PIX_FMT_RGB24,300,300);
}
运行此
的gcc -I $ HOME /的ffmpeg /包括program.c
给误差
/tmp/ccxMLBme.o:在函数'主':
。program.c :(文字+为0x18):未定义的参考`avpicture_get_size
collect2:劳工处返回1退出状态
然而,avpicture_get_size定义。为什么会出现这种情况?
然而,avpicture_get_size定义。
块引用>没有,作为标题(
< libav codeC / AV codec.h>
)刚声明它。在定义是库本身。
所以,你可能要添加链接器选项链接调用gcc的时候
libav codeC
:-lav codeC
另外请注意,库需要在命令行上指定的在文件需要他们:
的gcc -I $ HOME /的ffmpeg /包括program.c -lav codeC
不可以是这样的:
GCC -lav codeC -I $ HOME /的ffmpeg /包括program.c
更新:
参照的 Wyzard 的的评论完整的命令可能是这样的:
的gcc -I $ HOME /的ffmpeg /包括program.c -L $ HOME / ffmpeg的/ lib目录-lav codeC
有关不存储在接头标准位置的选项
-L
图书馆指定使用-l </指定查找库的addtional搜索路径code>选择,那就是
libav codec.xyz
在这种情况下。有关GCC的链接器选项的详细参考,请阅读这里。
I would like to compile this.
program.c
#include <libavcodec/avcodec.h> int main(){ int i = avpicture_get_size(AV_PIX_FMT_RGB24,300,300); }
Running this
gcc -I$HOME/ffmpeg/include program.c
gives error
/tmp/ccxMLBme.o: In function `main': program.c:(.text+0x18): undefined reference to `avpicture_get_size' collect2: ld returned 1 exit status
However, avpicture_get_size is defined. Why is this happening?
解决方案However, avpicture_get_size is defined.
No, as the header (
<libavcodec/avcodec.h>
) just declares it.The definition is in the library itself.
So you might like to add the linker option to link
libavcodec
when invoking gcc:-lavcodec
Please also note that libraries need to be specified on the command line after the files needing them:
gcc -I$HOME/ffmpeg/include program.c -lavcodec
Not like this:
gcc -lavcodec -I$HOME/ffmpeg/include program.c
Update:
Referring to Wyzard's comment the complete command might look like this:
gcc -I$HOME/ffmpeg/include program.c -L$HOME/ffmpeg/lib -lavcodec
For libraries not stored in the linkers standard location the option
-L
specifies an addtional search path to lookup libraries specified using the-l
option, that islibavcodec.x.y.z
in this case.
For a detailed reference on gcc's linker option, please read here.
这篇关于GCC:未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!