Original link: https://blog.frytea.com/archives/641/
Recently, the following error occurred when porting a C project:
xxxxxx.c:990:4: error: ignoring return value of 'chroot', declared with attribute warn_unused_result [-Werror=unused-result] 990 | chroot("/");
The reason why the error level is Error is because GCC compiles with the parameter -Werror
, which treats warnings as errors:
gcc -std=gnu99 -Wall -Werror -Wno-unknown-pragmas -Wno-strict-aliasing -Wpedantic -g -O2 -Wl,-z,relro -I. -D_FILE_OFFSET_BITS=64 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/fuse -c -o xxxxxx.o xxxxxx.c -MMD -MT pmxcfs.o -MF xxxxxx.od
Removing this compilation parameter can cure the symptoms but not the root cause. The most fundamental solution is to go to the source code to find the problem, deal with the return value, or manually ignore the error and add comments:
- chown(RUNDIR, 0, cfs.gid); + # TODO 临时处理,忽略返回值+ # 后期需根据实际情况处理错误码+ if(chown(RUNDIR, 0, cfs.gid)){};
Compile again to solve.
references
This article is reprinted from: https://blog.frytea.com/archives/641/
This site is for inclusion only, and the copyright belongs to the original author.