0

Im currently following a book called 'Bare Metal C' by Stephen Oualline and i got stuck trying to run a couple of commands on chapter 1. The first command is supposed to ask for an assembly language listing that prints the machine code in human-readable format, with the corresponding assembly language statements that generated that code. The other command tells the gcc command to pass flags to the linker so we an see a map of where the linker put things in memory. (just learning about all of this, please bear with me)

The commands i keyed in the terminal are as follows

Assembly language statements listing:

gcc -Wall -Wextra -g -Wextra -Wa,-a=hello.lst -c hello.c

Error:

clang: error: unsupported argument '-a=hello.lst' to option '-Wa,'

Linker map:

gcc -Wall -Wextra -static -Wl,-Map=hello.map -o hello hello.o

Error:

ld: library not found for -lcrt0.o clang: error: linker command failed with exit code 1 (use -v to see invocation)

Edit:(Couldn't fit it all in one comment, I'm responding to Clifford) Forgot to mention that I'm very fresh to programming let alone embedded systems so as I may not understand everything you're saying, ill attempt to decipher it and I hope you'll tell me if I'm hot or cold. Now, I'm aware that Clang is the default compiler for macOS, and so according to you, macOS decided to use Clang over GCC which I specified ( ill look into that later). As for everything else you've said I've no clue. After a quick Google search, I found out that ARM and x86 are different types of chip architectures. And the NUCLEO board I have contains an ARM chip so I'm unclear on what you mean there when you say it's not "bare metal" or "embedded". Second, the book told me that GCC was supposedly already installed as part of a developer package for macOS, there was no mention of having to install a GCC cross-compiler. As for ST's STM32CubeIDE, ill have to research and get familiar with it. I know this site isn't dedicated to teaching novices so I won't expect a detailed, dumbed-down response, maybe just a referral to somewhere where I could better learn this stuff. Regardless, thank you for your patience and time Clifford

  • Seems to be about the same question as [this](https://stackoverflow.com/q/24603910/2189500). – David Wohlferd Jun 23 '23 at 03:09
  • 1
    What is your embedded target architecture/processor? Knowing that will enable advice on what toolchain you need, because the native MacOS compiler is not it. – Clifford Jun 23 '23 at 12:14
  • The close vote citing a duplicate is incorrect IMO - that is for sure how to get an assembly listing from clang, but the question is an X-Y problem. The real problem is that Mohab is invoking the wrong compiler given that the book he is following is on embedded development on STM32. The close vote for this not being about software development is just bizarre. – Clifford Jun 23 '23 at 16:27
  • The book has some pretty scathing reviews - especially regarding getting the recommended toolchain installed and working. It seems however you have installed no toolchain at all. – Clifford Jun 23 '23 at 16:36
  • Re. _"I'm unclear on what you mean there when you say it's not "bare metal" or "embedded""_ : I am referring to the compiler. It is the _native_ compiler for building MacOS applications _on_ MacOS. It is not suitable for building embedded code for an entirely different architecture (ARM Cortex-M) with _no_ OS (that is what "bare-metal" refers to. For that you need a cross-compiler; that is a compiler _hosted_ on MacOS, but generating gode for the Nucleo board. – Clifford Jun 23 '23 at 19:12
  • You would do well to ignore the book for now (or entirely), install ST's free toolchain as I suggested, and load, build and run one of the demo projects they include for exactly your board. Then perhaps return to the book, but use the CubeIDE instead of the author's suggested tools. – Clifford Jun 23 '23 at 19:16
  • You could also use mbed https://os.mbed.com/. Your Nucleo board is directly supported by it, and you need not install anything - there is an entirely cloud based toolchain for that. – Clifford Jun 23 '23 at 19:22
  • Start here: https://embeddedexplorer.com/stm32cubeide-tutorial – Clifford Jun 23 '23 at 19:25

1 Answers1

1

Interesting that you invoke gcc but get a clang error. Apple decided to force the use of clang over gcc as described here: Mac clang installation seems to override GCC install.

However that invokes the native MacOS compiler, and is not "bare metal" or "embedded" and will target x86 or ARM depending on your Mac. Presumably the book and intends you to have installed a gcc cross compiler. Instead of gcc it's driver will be called something like arm-none-eabi-gcc (for ARM bare-metal in this example). If you have installed an appropriate toolchain, you probably need to be explicit about the gcc driver you are invoking.

You can of course get clang/LLVM to output an assembler listing, but given the subject of the book and your question tags, I suspect that is not what you need.

The book targets an STM32 Nucleo board. For that I suggest you install ST's STM32CubeIDE for Mac. It includes an appropriate gcc toolchain, and you need not use the IDE (Eclipse based) if you choose to follow the book. As above however you will need to ensure you are invoking the cross-tool, not the native compiler.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 1
    MacOS doesn't "force" clang, it just installs a `gcc` that's an alias for clang, probably because many Makefiles use `CC=gcc`, not just `cc`. And `clang` is intentionally mostly option-compatible with `gcc`, supporting stuff like `-march=native` and `-ffast-math`. But yes this has major downsides for people asking questions when they say they're using GCC without realizing their `gcc` command isn't running the GNU Compiler Collection. You can install actual GCC and put it earlier in your `$PATH` if you want it. – Peter Cordes Jun 23 '23 at 13:06
  • @PeterCordes : That is not quite what I said. I said _Apple_ did that (as a policy decision). That is they decided to "encourage" use of clang by making gcc requests redirect to clang. Perhaps "force" was a little strong - you can still run gcc if you choose, but it would need the be an active decision. But in this case the OP is running the native compiler instead of the intended cross-compiler, so it is largely academic. – Clifford Jun 23 '23 at 16:20
  • Yeah, I just intended a wording nitpick that "force" was too strong, and ended up writing more than was useful about why the decision to install Clang as `gcc` isn't crazy. The title of the question you linked makes it sound like MacOS did more to stop use of real GCC, but that was just a PATH misconfiguration. – Peter Cordes Jun 23 '23 at 16:23
  • @PeterCordes Understood. – Clifford Jun 23 '23 at 16:38
  • Sorry, couldn't fit my response so I edited my original question and left it there. – Mohab Hussein Jun 23 '23 at 18:54