解决使用新版本 clang17 编译 FFmpeg 出错问题
解决使用新版本 clang17 编译 FFmpeg 出错问题
今天把代码切到了 23 年的一次提交,目的是复现当时的一个 bug,需要编译下 FFmpeg 4,当我开始编译时遇到了下面两个编译问题,其实在升级编译脚本时也遇到了,当时没有做记录,这次刚好记录一下。
我的 clang 版本:
1
2
3
4
$ clang -v
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.5.0
Thread model: posix
之前为啥没有遇到这两个问题?猜测之前的编译器上是警告级别,现在新版本默认成错误了,使用 Xcode 的时候遇到过这种情况,这是为了引起开发者的注意,有的时候可能真的会酿成悲剧,不过这是 FFmpeg 的代码,目前没发现问题,所以我通过向编译器传递编译选项屏蔽错误的方式来解决:
编译 FFmpeg 的时候可以给 cflags 追加上 “-Wno-incompatible-function-pointer-types -Wno-int-conversion” 选项即可,注意需要重新 config,然后再编译,不重新 config 还是会报错。
函数参数类型不匹配
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
libavcodec/aarch64/h264dsp_init_aarch64.c:84:38: error: incompatible function pointer types assigning to 'h264_weight_func' (aka 'void (*)(unsigned char *, long, int, int, int, int)') from 'void (uint8_t *, int, int, int, int, int)' (aka 'void (unsigned char *, int, int, int, int, int)') [-Wincompatible-function-pointer-types]
84 | c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16_neon;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/aarch64/h264dsp_init_aarch64.c:85:38: error: incompatible function pointer types assigning to 'h264_weight_func' (aka 'void (*)(unsigned char *, long, int, int, int, int)') from 'void (uint8_t *, int, int, int, int, int)' (aka 'void (unsigned char *, int, int, int, int, int)') [-Wincompatible-function-pointer-types]
85 | c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_8_neon;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/aarch64/h264dsp_init_aarch64.c:86:38: error: incompatible function pointer types assigning to 'h264_weight_func' (aka 'void (*)(unsigned char *, long, int, int, int, int)') from 'void (uint8_t *, int, int, int, int, int)' (aka 'void (unsigned char *, int, int, int, int, int)') [-Wincompatible-function-pointer-types]
86 | c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_4_neon;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/aarch64/h264dsp_init_aarch64.c:88:40: error: incompatible function pointer types assigning to 'h264_biweight_func' (aka 'void (*)(unsigned char *, unsigned char *, long, int, int, int, int, int)') from 'void (uint8_t *, uint8_t *, int, int, int, int, int, int)' (aka 'void (unsigned char *, unsigned char *, int, int, int, int, int, int)') [-Wincompatible-function-pointer-types]
88 | c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16_neon;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/aarch64/h264dsp_init_aarch64.c:89:40: error: incompatible function pointer types assigning to 'h264_biweight_func' (aka 'void (*)(unsigned char *, unsigned char *, long, int, int, int, int, int)') from 'void (uint8_t *, uint8_t *, int, int, int, int, int, int)' (aka 'void (unsigned char *, unsigned char *, int, int, int, int, int, int)') [-Wincompatible-function-pointer-types]
89 | c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_8_neon;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/aarch64/h264dsp_init_aarch64.c:90:40: error: incompatible function pointer types assigning to 'h264_biweight_func' (aka 'void (*)(unsigned char *, unsigned char *, long, int, int, int, int, int)') from 'void (uint8_t *, uint8_t *, int, int, int, int, int, int)' (aka 'void (unsigned char *, unsigned char *, int, int, int, int, int, int)') [-Wincompatible-function-pointer-types]
90 | c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_4_neon;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.
make: *** [libavcodec/aarch64/h264dsp_init_aarch64.o] Error 1
make: *** Waiting for unfinished jobs....
指针转成整型类型不兼容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
libavutil/dict.c:166:15: error: incompatible pointer to integer conversion initializing 'uintptr_t' (aka 'unsigned long') with an expression of type 'void *' [-Wint-conversion]
166 | uintptr_t ptr = NULL;
| ^ ~~~~
libavutil/dict.c:171:12: error: incompatible pointer to integer conversion returning 'void *' from a function with result type 'uintptr_t' (aka 'unsigned long') [-Wint-conversion]
171 | return NULL;
| ^~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include/__stddef_null.h:26:14: note: expanded from macro 'NULL'
26 | #define NULL ((void*)0)
| ^~~~~~~~~~
libavutil/dict.c:166:15: warning: unused variable 'ptr' [-Wunused-variable]
166 | uintptr_t ptr = NULL;
| ^~~
libavutil/dict.c:175:14: error: incompatible pointer to integer conversion initializing 'uintptr_t' (aka 'unsigned long') with an expression of type 'void *' [-Wint-conversion]
175 | uintptr_t ptr = NULL;
| ^ ~~~~
libavutil/dict.c:178:15: error: incompatible pointer to integer conversion returning 'void *' from a function with result type 'uintptr_t' (aka 'unsigned long') [-Wint-conversion]
178 | return NULL;
| ^~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include/__stddef_null.h:26:14: note: expanded from macro 'NULL'
26 | #define NULL ((void*)0)
| ^~~~~~~~~~
libavutil/dict.c:182:15: error: incompatible pointer to integer conversion returning 'void *' from a function with result type 'uintptr_t' (aka 'unsigned long') [-Wint-conversion]
182 | return NULL;
| ^~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/17/include/__stddef_null.h:26:14: note: expanded from macro 'NULL'
26 | #define NULL ((void*)0)
| ^~~~~~~~~~
libavutil/dict.c:189:48: warning: format specifies type 'void *' but the argument has type 'uintptr_t' (aka 'unsigned long') [-Wformat]
189 | snprintf(valuestr, sizeof(valuestr), "%p", value);
| ~~ ^~~~~
| %lu
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include/secure/_stdio.h:60:62: note: expanded from macro 'snprintf'
60 | __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
| ^~~~~~~~~~~
3 warnings and 5 errors generated.
make: *** [libavutil/dict.o] Error 1
make: *** Waiting for unfinished jobs....
2 warnings generated.
24 warnings generated.
本文由作者按照 CC BY 4.0 进行授权