背景

最新换了台新电脑,以前电脑是ubuntu16环境,openwrt15编译通过,但是新电脑装的是Ubuntu20(Ubuntu16/18怎么都装不上,可能是电脑硬件较新驱动不支持的原因),再编译openwrt15编译不过了,以下是编译过程中遇到的问题及解决办法,最终成功编译出产物了(MT7628平台)。

ubuntu20默认的gcc9版本太高了,怕有其它问题,所以首先我是将gcc进行降版本,并切换为gcc-4.8

Ubuntu20.04终端安装、切换低版本gcc/g++

sudo vim /etc/apt/sources.list
增加源
deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

更新源
sudo apt-get update

安装gcc5,g++5
sudo apt-get install g++-5 gcc-5

安装gcc4,g++4
sudo apt-get install g++-4.8 gcc-4.8

设置优先级
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-4.8 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-5 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-9 90

选择gcc版本
sudo update-alternatives --config gcc

编译报错(1):

freadahead.c: In function 'freadahead':
freadahead.c:91:3: error: #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
   91 |  #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
      |   ^~~~~
make[7]: *** [Makefile:1837: freadahead.o] Error 1
make[7]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/m4-1.4.17/lib'

修改:

cd build_dir/host/m4-1.4.17/
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h

参考:http://www.voycn.com/article/bianyimoujiyuopenwrtdesdk

编译报错(2):

lib/fseterr.c: In function 'fseterr':
lib/fseterr.c:77:3: error: #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
   77 |  #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
      |   ^~~~~
make[6]: *** [Makefile:3414: lib/fseterr.o] Error 1
make[6]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/bison-3.0.2'

修改:

cd build_dir/host/bison-3.0.2/
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h

编译报错(3):

cc -o make_ext4fs allocate.o canned_fs_config.o contents.o crc16.o ext4fixup.o ext4_sb.o ext4_utils.o extent.o indirect.o make_ext4fs_main.o make_ext4fs.o sha1.o uuid.o wipe.o libsparse/libsparse.a -lz
/bin/ld: contents.o: in function `make_special':
contents.c:(.text+0xbf7): undefined reference to `major'
/bin/ld: contents.c:(.text+0xc17): undefined reference to `minor'
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:24: make_ext4fs] Error 1
make[4]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/make-ext4fs-2015-05-01'
make[3]: *** [Makefile:37: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/make-ext4fs-2015-05-01/.built] Error 2

修改:

vim build_dir/host/make-ext4fs-2015-05-01/contents.c 中添加 #include <sys/sysmacros.h>

编译报错(4):

/bin/ld: ../lib/libblkid.a(devname.o): in function `probe_all':
devname.c:(.text+0x888): undefined reference to `makedev'
/bin/ld: devname.c:(.text+0xb7e): undefined reference to `makedev'
/bin/ld: devname.c:(.text+0xc5b): undefined reference to `makedev'
collect2: error: ld returned 1 exit status
make[6]: *** [Makefile:391: e2fsck] Error 1
make[6]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/e2fsprogs-1.42.8/e2fsck'

修改:

vim build_dir/host/e2fsprogs-1.42.8/lib/blkid/devname.c 中添加 #include <sys/sysmacros.h>

编译报错(5):

  LD      mkfs.jffs2
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.o: in function `write_special_file':
/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:944: undefined reference to `major'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:944: undefined reference to `minor'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.o: in function `recursive_populate_directory':
/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:1273: undefined reference to `minor'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:1273: undefined reference to `major'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:1263: undefined reference to `minor'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:1263: undefined reference to `major'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.o: in function `interpret_table_entry':
/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:467: undefined reference to `makedev'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:503: undefined reference to `makedev'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c:510: undefined reference to `makedev'

修改:

vim build_dir/host/mtd-utils-1.5.1/mkfs.jffs2.c 中添加 #include <sys/sysmacros.h>
vim build_dir/host/mtd-utils-1.5.1/ubi-utils/libubi.c  中添加 #include <sys/sysmacros.h>
vim build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/devtable.c 中添加 #include <sys/sysmacros.h>
vim build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs.c 中添加 #include <sys/sysmacros.h>

编译报错(6):

make[4]: Entering directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1'
  CHK     include/version.h
  CC      mkfs.ubifs/devtable.o
  CC      mkfs.ubifs/hashtable/hashtable.o
  CC      mkfs.ubifs/hashtable/hashtable_itr.o
  LD      mkfs.ubifs/mkfs.ubifs
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs.o: in function `add_dev_inode':
/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs.c:1157: undefined reference to `minor'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs.c:1157: undefined reference to `major'
/bin/ld: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs.c:1157: undefined reference to `makedev'
collect2: error: ld returned 1 exit status
make[4]: *** [common.mk:71: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs] Error 1
make[4]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1'
make[3]: *** [Makefile:56: /home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/mtd-utils-1.5.1/.built] Error 2
make[3]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/tools/mtd-utils'
make[2]: *** [tools/Makefile:123: tools/mtd-utils/compile] Error 2
make[2]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628'
make[1]: *** [tools/Makefile:121: /home/yang/Work/JS7628/openwrt_-js7628/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628'
make: *** [/home/yang/Work/JS7628/openwrt_-js7628/include/toplevel.mk:183: world] Error 2

修改:

vim build_dir/host/mtd-utils-1.5.1/mkfs.ubifs/mkfs.ubifs.c 中添加 #include <sys/sysmacros.h>

还有不少这样类似的未定义报错,都是类似的修改方法,在对应的文件中添加 #include <sys/sysmacros.h> 这里就不一一列出来了

编译报错(7):

freadahead.c: In function 'freadahead':
freadahead.c:64:3: error: #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread on your system, then report this to bug-gnulib."
   64 |  #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread on your system, then report this to bug-gnulib."
      |   ^~~~~
make[8]: *** [Makefile:890: freadahead.o] Error 1
make[8]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/findutils-4.4.2/gnulib/lib'
make[7]: *** [Makefile:696: all] Error 2
make[7]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/findutils-4.4.2/gnulib/lib'
make[6]: *** [Makefile:606: all-recursive] Error 1
make[6]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/findutils-4.4.2/gnulib'
make[5]: *** [Makefile:643: all-recursive] Error 1
make[5]: Leaving directory '/home/yang/Work/JS7628/openwrt_-js7628/build_dir/host/findutils-4.4.2'
make[4]: *** [Makefile:582: all] Error 2

修改:

cd build_dir/host/findutils-4.4.2
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h

sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gnulib/lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> gnulib/lib/stdio-impl.h
echo "#define _IO_ferror_unlocked" >> gnulib/lib/stdio-impl.h
sed -i '/unistd/a #include <sys/sysmacros.h>' gnulib/lib/mountlist.c

这个问题仍然没有解决,然后更换findutils-4.4.2为findutils-4.6.0,继续报错如下:

freadahead.c: In function 'freadahead':
freadahead.c:92:3: error: #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
  #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
   ^
make[9]: *** [Makefile:2225: freadahead.o] Error 1
make[9]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/findutils-4.6.0/gl/lib'
make[8]: *** [Makefile:2250: all-recursive] Error 1
make[8]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/findutils-4.6.0/gl/lib'
make[7]: *** [Makefile:1931: all] Error 2
make[7]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/findutils-4.6.0/gl/lib'
make[6]: *** [Makefile:1657: all-recursive] Error 1
make[6]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/findutils-4.6.0/gl'
make[5]: *** [Makefile:1706: all-recursive] Error 1

修改:

cd build_dir/host/findutils-4.6.0
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h

sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gl/lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> gl/lib/stdio-impl.h
sed -i '/unistd/a #include <sys/sysmacros.h>' gl/lib/mountlist.c

编译报错(8):

/usr/bin/ld: cmListFileLexer.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: ProcessUNIX.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:2: cmake] Error 1
make[4]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/cmake-2.8.12.2/Bootstrap.cmk'
---------------------------------------------
Error when bootstrapping CMake:
Problem while running make
---------------------------------------------
Log of errors: /home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/cmake-2.8.12.2/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
make[3]: *** [Makefile:28: /home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/cmake-2.8.12.2/.configured] Error 9
make[3]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/tools/cmake'
make[2]: *** [tools/Makefile:123: tools/cmake/compile] Error 2
make[2]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628'
make[1]: *** [tools/Makefile:121: /home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628'
make: *** [/home/yang/Work/openwrt/JS7628/openwrt_-js7628/include/toplevel.mk:183: world] Error 2

修改:

这个问题是我自己修改的(如果有更好的修改方法,请忽略这里的描述):
修改cmake-2.8.12.2下的bootstrap文件,在第765行之后添加
cmake_c_flags="${CFLAGS} -fpic -fPIC -fpie -fPIE"

第815行之后添加
cmake_cxx_flags="${CXXFLAGS} -fpic -fPIC -fpie -fPIE"

其余文件有类似报错,只需要在对应路径下的CMakeLists.txt文件添加如下代码即可编译通过
foreach(lang C CXX)
  set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wno-format -fpic -fPIC -fpie -fPIE")
endforeach()

编译报错(9):

mksquashfs.c: In function 'create_inode':
mksquashfs.c:1372:29: error: called object 'major' is not a function or function pointer
   unsigned int major = major(buf->st_rdev);
                             ^
mksquashfs.c:1372:16: note: declared here
   unsigned int major = major(buf->st_rdev);
                ^
mksquashfs.c:1373:29: error: called object 'minor' is not a function or function pointer
   unsigned int minor = minor(buf->st_rdev);
                             ^
mksquashfs.c:1373:16: note: declared here
   unsigned int minor = minor(buf->st_rdev);
                ^
mksquashfs.c:1396:29: error: called object 'major' is not a function or function pointer
   unsigned int major = major(buf->st_rdev);
                             ^
mksquashfs.c:1396:16: note: declared here
   unsigned int major = major(buf->st_rdev);
                ^
mksquashfs.c:1397:29: error: called object 'minor' is not a function or function pointer
   unsigned int minor = minor(buf->st_rdev);
                             ^
mksquashfs.c:1397:16: note: declared here
   unsigned int minor = minor(buf->st_rdev);
                ^
mksquashfs.c: In function 'dir_scan2':
mksquashfs.c:3796:3: warning: implicit declaration of function 'makedev' [-Wimplicit-function-declaration]
   buf.st_rdev = makedev(pseudo_ent->dev->major,

修改:

vim build_dir/host/squashfs4.2/squashfs-tools/mksquashfs.c 添加 #include <sys/sysmacros.h>

编译报错(10):

gcc   unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o unsquash-4.o swap.o compressor.o gzip_wrapper.o lzma_xz_wrapper.o xz_wrapper.o lzma_xz_options.o /home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/host/lib/liblzma.a -lpthread -lm -lz -o unsquashfs
/usr/bin/ld: unsquashfs.o: in function `create_inode':
unsquashfs.c:(.text+0x2456): undefined reference to `makedev'
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:242: unsquashfs] Error 1
make[4]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/squashfs4.2/squashfs-tools'
make[3]: *** [Makefile:43: /home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/host/squashfs4.2/.built] Error 2
make[3]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/tools/squashfs4'
make[2]: *** [tools/Makefile:123: tools/squashfs4/compile] Error 2
make[2]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628'
make[1]: *** [tools/Makefile:121: /home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628'

修改:

vim build_dir/host/squashfs4.2/squashfs-tools/unsquashfs.c 添加 #include <sys/sysmacros.h>

编译报错(11):

checking for the correct version of the gmp/mpfr/mpc libraries... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.
make[3]: *** [Makefile:47: /home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04-minimal/.configured] Error 1

修改:

在tools下面其实本来就有gmp/mpfr/mpc这三个库的源码,只是我们采用默认的编译方式
make tools/gmp/compile V=s
make tools/mpfr/compile V=s
make tools/mpc/compile V=s

修改对应的tools/xxxx/Makefile(xxxx表示上述三个库)
增加配置参数
	CFLAGS=-fPIE CPPFLAGS=-fPIE

在build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/configure
第5665行增加have_gmp=yes,
(这里是规避方法,不让报错,因为这三个库我们在上面是指定编译参数单独手动安装的)

编译报错(12):

In file included from /home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/cp/except.c:1008:
cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute
cfns.gperf:26:14: note: 'const char* libc_name_p(const char*, unsigned int)' previously declared here
cfns.gperf:26:14: warning: inline function 'const char* libc_name_p(const char*, unsigned int)' used but never defined
make[6]: *** [Makefile:1058: cp/except.o] Error 1

修改:

//cfns.h 第55~56行中间插入
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif

//cfns.gperf 第24~25行中间插入
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif

编译报错(13):

make[6]: Entering directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src'
gawk -f ./mkerrnos.awk ./errnos.in >code-to-errno.h
gawk: ./mkerrnos.awk:86: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkerrcodes1.awk ./errnos.in >_mkerrcodes.h
gawk: ./mkerrcodes1.awk:84: warning: regexp escape sequence `\#' is not a known regexp operator
mipsel-openwrt-linux-uclibc-gcc -E -I/home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/include -I/home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/include -I/home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/usr/include -I/home/yang/Work/openwrt/JS7628/openwrt_-js7628/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/include   _mkerrcodes.h | grep GPG_ERR_ | \
               gawk -f ./mkerrcodes.awk >mkerrcodes.h
gawk: ./mkerrcodes.awk:88: warning: regexp escape sequence `\#' is not a known regexp operator
rm _mkerrcodes.h
cc -I. -I. -o mkerrcodes ./mkerrcodes.c
./mkerrcodes | gawk -f ./mkerrcodes2.awk >code-from-errno.h
gawk: ./mkerrcodes2.awk:94: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkstrtable.awk -v textidx=2 -v nogettext=1 \
        ./err-sources.h.in >err-sources-sym.h
gawk: ./mkstrtable.awk:113: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkstrtable.awk -v textidx=2 -v nogettext=1 \
        ./err-codes.h.in >err-codes-sym.h
gawk: ./mkstrtable.awk:113: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkstrtable.awk -v textidx=2 -v nogettext=1 \
        -v prefix=GPG_ERR_ -v namespace=errnos_ \
        ./errnos.in >errnos-sym.h
gawk: fatal: cannot use gawk builtin `namespace' as variable name
make[6]: *** [Makefile:1020: errnos-sym.h] Error 2

修改:

cd build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12

修改这几个文件:
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/lang/cl/mkerrcodes.awk
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/mkerrcodes.awk
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/mkerrcodes1.awk
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/mkerrcodes2.awk
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/mkerrnos.awk
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/mkstrtable.awk

分别找到如下代码:
!header {
  sub (/\#.+/, "");

将上述所有文件中的所有"sub (/\#.+/, "");",改为:“sub (/#.+/, "");”,也就是说最新的gawk能够识别到’#'号不需要使用转义字符(‘\‘)的帮助

找到,如下几个文件:
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/Makefile
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/Makefile.am
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/Makefile.in
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/mkstrtable.awk

打开上述文件,搜索“namespace”,将所有搜索到的结果替换为“pkg_namespace”

编译报错(14):

In file included from strerror-sym.c:30:0:
errnos-sym.h:318:1: error: redefinition of 'msgidxof'
 msgidxof (int code)
 ^
In file included from strerror-sym.c:29:0:
err-codes-sym.h:548:1: note: previous definition of 'msgidxof' was here
 msgidxof (int code)
 ^
make[7]: *** [Makefile:645: gpg_error-strerror-sym.o] Error 1
make[7]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src'
make[6]: *** [Makefile:386: all] Error 2
make[6]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src'

修改:

该函数在头文件中重复定义了,注释掉一个即可
vim build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src/errnos-sym.h

#if 0
static GPG_ERR_INLINE int
msgidxof (int code)
{
  return (0 ? 0
  : ((code >= 0) && (code <= 140)) ? (code - 0)
  : -1);
}
#endif

编译报错(15):

gpg_error-strerror-sym.o: In function `gpg_strerror_sym':
strerror-sym.c:(.text+0x20): undefined reference to `errnos_msgidxof'
collect2: error: ld returned 1 exit status
make[7]: *** [Makefile:506: gpg-error] Error 1
make[7]: Leaving directory '/home/yang/Work/openwrt/JS7628/openwrt_-js7628/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgpg-error-1.12/src'
make[6]: *** [Makefile:386: all] Error 2

修改:

函数未定义报错,修改为上述定义的函数即可。
//idx = errnos_msgidxof (code);
idx = msgidxof (code);

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐