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:未定义的引用


- Stroustrup 的 Simple_window.h 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01