【发布时间】:2018-06-27 16:51:43
【问题描述】:
我想在 Eclipse(在 Windows 中)中为 Raspberry 编译一个应用程序。我安装了 SysGCC,为交叉编译配置了 Eclipse。如果我创建类似“Hello world”的东西 - 一切都很好。 Eclipse 创建了可以在 Raspberry 上完美运行的二进制文件。 但我需要在我的应用程序中使用 FFMPEG 库。这里是应用程序的最小代码:
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
int main(void) {
av_register_all();
return EXIT_SUCCESS;
}
我在项目配置中添加了库。项目编译好,但是链接器报错很多:
C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\usr\local\lib\libavcodec.a(aaccoder.o): In function `quantize_and_encode_band_cost_template':
/usr/src/ffmpeg/libavcodec/aacenc_quantization.h:108: undefined reference to `cbrtf'
/usr/src/ffmpeg/libavcodec/aacenc_quantization.h:108: undefined reference to `cbrtf'
/usr/src/ffmpeg/libavcodec/aacenc_quantization.h:108: undefined reference to `cbrtf'
/usr/src/ffmpeg/libavcodec/aacenc_quantization.h:108: undefined reference to `cbrtf'
C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\usr\local\lib\libavcodec.a(aacenc_is.o): In function `quantize_and_encode_band_cost_template':
/usr/src/ffmpeg/libavcodec/aacenc_quantization.h:108: undefined reference to `cbrtf'
C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\usr\local\lib\libavcodec.a(aacenc_is.o):/usr/src/ffmpeg/libavcodec/aacenc_quantization.h:108: more undefined references to `cbrtf' follow
C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\usr\local\lib\libavcodec.a(adx.o): In function `ff_adx_calculate_coeffs':
/usr/src/ffmpeg/libavcodec/adx.c:30: undefined reference to `cos'
/usr/src/ffmpeg/libavcodec/adx.c:34: undefined reference to `lrintf'
/usr/src/ffmpeg/libavcodec/adx.c:35: undefined reference to `lrintf'
/usr/src/ffmpeg/libavcodec/adx.c:30: undefined reference to `cos'
/usr/src/ffmpeg/libavcodec/adx.c:34: undefined reference to `lrintf'
/usr/src/ffmpeg/libavcodec/adx.c:35: undefined reference to `lrintf'
collect2.exe: error: ld returned 1 exit status
make: *** [ffmpeg] Error 1
02:21:24 Build Finished (took 8s.394ms)
已解决:
我使用了下一个命令:
arm-linux-gnueabihf-gcc -L"C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\usr\local\lib" -L"C:\SysGCC\Raspberry\arm-linux-gnueabihf\lib" -o "ffmpeg" ./src/ffmpeg.o -lc -lm -lpthread -lavformat -lavcodec -lswscale -lavutil -lavfilter -lavdevice -lswresample -lpostproc -ldl -lx264 -lgcc -lz
其中 -lc -lm -lpthread -lavformat -lavcodec -lswscale -lavutil -lavfilter -lavdevice -lswresample -lpostproc -ldl -lx264 -lgcc -lz 是库链接器需要的(也许不是所有他们)。 请注意顺序很重要。
【问题讨论】:
-
如果缺少
cos,是否包含math链接库? -
您使用哪些编译器标志来编译库?请务必启用浮点支持。
-
您缺少头文件,只需在互联网上查找并将其包含在相应的 C 源中即可。
-
@LethalProgrammer 如果编译工作但链接器抱怨,那么标题显然没有丢失。而是在链接期间不包含该库。