-1

I'm trying to compile my own custom kernel for Android using the toolchain from Android NDK r16b. I get the kernel source code at here. I never modified the source code of the kernel (specifically that part). And this is the problem I had while compiling it.

/root/custom-kernel/kernel/Xiaomi_Kernel_OpenSource-cactus-o-oss/drivers/misc/mediatek/base/power/mcdi/mcdi_v1/mtk_mcdi_profile.c: In function 'mcdi_profile_read':
/root/custom-kernel/kernel/Xiaomi_Kernel_OpenSource-cactus-o-oss/drivers/misc/mediatek/base/power/mcdi/mcdi_v1/mtk_mcdi_profile.c:239:2: error: missing braces around initializer [-Werror=missing-braces]
  } cnt[2] = {0};
  ^
/root/custom-kernel/kernel/Xiaomi_Kernel_OpenSource-cactus-o-oss/drivers/misc/mediatek/base/power/mcdi/mcdi_v1/mtk_mcdi_profile.c:239:2: error: (near initialization for 'cnt[0].sec') [-Werror=missing-braces]
cc1: all warnings being treated as errors

This is the part of the code that produces the error. If you want to see the full kernel compilation log,you can check it in here. This is the steps that i do for compiling the kernel :

export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=/root/custom-kernel/kernel/toolchain/bin/arm-linux-androideabi-
cd /root/custom-kernel/kernel/Xiaomi_Kernel_OpenSource-cactus-o-oss
make clean
make mrproper
mkdir ../out
make O=../out cereus_defconfig
cd ../out
make

I already try the solution from here and it's still doesn't fix it. Any answer/help is appreciated!

  • 1
    Have you written or modified the code that the compiler is complaining about? Please show more context so we can see more than just the single out-of-context line reported by the compiler. – Some programmer dude Jul 09 '21 at 06:49
  • Please take some time to refresh [the help pages](http://stackoverflow.com/help), especially ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also take the [tour] and read about [ask] good questions and [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly don't forget how to create a [mcve]. – Some programmer dude Jul 09 '21 at 07:01
  • You need to specify at least, the compiler name, version, platform and the source's version and compile time parameters. I think the error you're seeing is related to zero initializing array elements (`{0}`) when the array elements themselves are some structs or other composite data types. You can try with `--std=c11` compiler option or use `gnu` extensions. Or, you can try modifying the code to `{{0}}` (notice extra braces) – Fractal Jul 09 '21 at 07:17
  • @Fractal I already try that and unfortunately it doesn't fix the problem. – GetRektBoy724 Jul 09 '21 at 07:41
  • Well, initializing a **structure** type with a **plain** ``0`` doesn't look as correct one: https://github.com/MiCode/Xiaomi_Kernel_OpenSource/blob/cactus-o-oss/drivers/misc/mediatek/base/power/mcdi/mcdi_v1/mtk_mcdi_profile.c#L239. (Existing braces around ``0`` are consumed by the array initialization.). Initializer `{{{0}}}` should help: the first pair of braces is for array of unnamed structures, the second pair of braces is for the fields of that structure, and the third pair of braces is for initialize elements of `sec` array. – Tsyvarev Jul 09 '21 at 08:17
  • @Tsyvarev thanks for answering,gonna try it ASAP – GetRektBoy724 Jul 09 '21 at 11:09

1 Answers1

0

I fixed the problem with replacing the {0} with {{{0}}} as @Tsyvarev said in the comment

Well, initializing a structure type with a plain 0 doesn't look as correct one: github.com/MiCode/Xiaomi_Kernel_OpenSource/blob/cactus-o-oss/…. (Existing braces around 0 are consumed by the array initialization.). Initializer {{{0}}} should help: the first pair of braces is for array of unnamed structures, the second pair of braces is for the fields of that structure, and the third pair of braces is for initialize elements of sec array.