gcc: undefined reference to(gcc:未定义的引用)
问题描述
我想编译这个.
program.c
#include <libavcodec/avcodec.h>
int main(){
int i = avpicture_get_size(AV_PIX_FMT_RGB24,300,300);
}
运行这个
gcc -I$HOME/ffmpeg/include program.c
报错
/tmp/ccxMLBme.o: In function `main':
program.c:(.text+0x18): undefined reference to `avpicture_get_size'
collect2: ld returned 1 exit status
然而,定义了avpicture_get_size.为什么会发生这种情况?
However, avpicture_get_size is defined. Why is this happening?
推荐答案
但是,定义了 avpicture_get_size.
However, avpicture_get_size is defined.
不,因为标题 () 只是声明它.
No, as the header (<libavcodec/avcodec.h>) just declares it.
定义在图书馆本身.
因此,您可能希望在调用 gcc 时添加链接器选项以链接 libavcodec:
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
不是像这样:
gcc -lavcodec -I$HOME/ffmpeg/include program.c
参考Wyzard的评论,完整的命令可能如下所示:
Referring to Wyzard's comment, the complete command might look like this:
gcc -I$HOME/ffmpeg/include program.c -L$HOME/ffmpeg/lib -lavcodec
对于没有存储在链接器标准位置的库,选项 -L 指定一个额外的搜索路径来查找使用 -l 选项指定的库,即 libavcodec.xyz 在这种情况下.
For libraries not stored in the linkers standard location the option -L specifies an additional search path to lookup libraries specified using the -l option, that is libavcodec.x.y.z in this case.
有关 GCC 链接器选项的详细参考,请阅读此处.
For a detailed reference on GCC's linker option, please read here.
这篇关于gcc:未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:gcc:未定义的引用
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
