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: exports not consumed by Makefiles #67

Closed the-real-neil closed 10 months ago

the-real-neil commented 10 months ago

If Chapter02/set-path-arm-cortex_a8-linux-gnueabihf does this...

PATH=${HOME}/x-tools/arm-cortex_a8-linux-gnueabihf/bin/:$PATH
export CROSS_COMPILE=arm-cortex_a8-linux-gnueabihf-
export ARCH=arm

...then why are those variables never consumed by any of the following Makefiles?

Indeed, because the CROSS_COMPILE prefix is never used, it is the host's CC that is invoked. Indeed, the README shows exactly that:

https://github.com/PacktPublishing/Mastering-Embedded-Linux-Programming-Third-Edition/blob/c1424a5d8088df491b1abdc6d98671936e1bd6ca/Chapter02/library/README#L43

You should have two executables: hello-arm-shared and hello-arm-static
$ list-libs hello-arm-shared 
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libtest.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

$ list-libs hello-arm-static 
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

The book, by contrast, uses the prefixed commands like this:

$ arm-cortex_a8-linux-gnueabihf-gcc -static helloworld.c -o helloworld-static

Is this discrepancy intentional? What purpose, if any, does the set-path-arm-cortex_a8-linux-gnueabihf script serve here?

fvasquez commented 10 months ago

@the-real-neil I don't think the examples from the section on Linking with libraries were meant to be cross-compiled. That is why the host's CC is invoked instead of the CROSS_COMPILE prefix.