PacktPublishing / Mastering-Embedded-Linux-Programming-Third-Edition

Mastering Embedded Linux Programming Third Edition, published by Packt
MIT License
532 stars 151 forks source link

Chapter02 Compile error using toolchain: cannot execute 'cc1' #63

Closed zximeng closed 1 year ago

zximeng commented 1 year ago

Followed the book instructions in Chapter 2. Used the same version of cross tool-ng, but encountered several errors such as wget timeouts and binutils " namespace 'std' does not name a type" when I tried to build the toolchain for arm A8. So then I switched to the master branch as suggested by the solution on GitHub. After I switched to the master branch, the build process for both arm A8 and QEMU went through without error. However, when I tried to compile the hello world program with arm A8 toolchain, it throws an error:

arm-cortex_a8-linux-gnueabihf-gcc hello.c -o helloworld
arm-cortex_a8-linux-gnueabihf-gcc: fatal error: cannot execute 'cc1': execvp: No such file or directory
compilation terminated.

I found the cc1 in the libexec/gcc/arm../13.2.0 folder and added the folder to the PATH in ~/.bashrc as follows

export PATH="
~/x-tools/arm-cortex_a8-linux-gnueabihf/bin:\
~/x-tools/arm-cortex_a8-linux-gnueabihf/libexec/gcc/arm-cortex_a8-linux-gnueabihf/13.2.0\
:$PATH"

But still getting the same error.

Then I tried the toolchain for QEMU and it works. I got a helloworld output with arm properties.

I used the -v to check the setting for two gcc. The configuration for qemu shows:

Using built-in specs. COLLECT_GCC=arm-unknown-linux-gnueabi-gcc COLLECT_LTO_WRAPPER=/home/simonzhang/x-tools/arm-unknown-linux-gnueabi/libexec/gcc/arm-unknown-linux-gnueabi/13.2.0/lto-wrapper Target: arm-unknown-linux-gnueabi Configured with: /home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-unknown-linux-gnueabi/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-unknown-linux-gnueabi --prefix=/home/simonzhang/x-tools/arm-unknown-linux-gnueabi --exec_prefix=/home/simonzhang/x-tools/arm-unknown-linux-gnueabi --with-sysroot=/home/simonzhang/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot --enable-languages=c,c++ --with-float=soft --with-pkgversion='crosstool-NG 1.25.0.212_285915c' --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-unknown-linux-gnueabi/buildtools --with-mpfr=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-unknown-linux-gnueabi/buildtools --with-mpc=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-unknown-linux-gnueabi/buildtools --with-isl=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-unknown-linux-gnueabi/buildtools --enable-lto --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/simonzhang/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot --enable-long-long Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.0 (crosstool-NG 1.25.0.212_285915c)

The configuration for A8 shows:

Using built-in specs. COLLECT_GCC=arm-cortex_a8-linux-gnueabihf-gcc Target: arm-cortex_a8-linux-gnueabihf Configured with: /home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-cortex_a8-linux-gnueabihf/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-cortex_a8-linux-gnueabihf --prefix=/home/simonzhang/x-tools/arm-cortex_a8-linux-gnueabihf --exec_prefix=/home/simonzhang/x-tools/arm-cortex_a8-linux-gnueabihf --with-sysroot=/home/simonzhang/x-tools/arm-cortex_a8-linux-gnueabihf/arm-cortex_a8-linux-gnueabihf/sysroot --enable-languages=c,c++ --with-cpu=cortex-a8 --with-fpu=neon --with-float=hard --with-pkgversion='crosstool-NG 1.25.0.212_285915c' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-cortex_a8-linux-gnueabihf/buildtools --with-mpfr=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-cortex_a8-linux-gnueabihf/buildtools --with-mpc=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-cortex_a8-linux-gnueabihf/buildtools --with-isl=/home/simonzhang/Desktop/crosstool/crosstool-ng/.build/arm-cortex_a8-linux-gnueabihf/buildtools --enable-lto --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/simonzhang/x-tools/arm-cortex_a8-linux-gnueabihf/arm-cortex_a8-linux-gnueabihf/sysroot --enable-long-long Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.0 (crosstool-NG 1.25.0.212_285915c)

I checked and found that for qemu, the toolchain has a wrapper. And the A8 has the hf settings. Other than that, I don't see any differences.

zximeng commented 1 year ago

I checked the ubuntu version. I was using 22.04 and the book is using 20.04. I switched to the 20.04 and went through the same process again and now it works. Seems like it is not working well on the newer ubuntu.