4ms / stm32mp1-baremetal

Baremetal framework and example projects for the STM32MP15x Cortex-A7 based MPU
Other
148 stars 28 forks source link

Building under linux, C++ projects are not building. C build fine #25

Closed codewitch-honey-crisis closed 4 months ago

codewitch-honey-crisis commented 4 months ago

UPDATE: This problem only occurs when using newer cross compiler toolchains than 12.3. Use the compiler version in the docs.

I'm getting the strangest error trying to build the C++ projects.

rm -rf build
honey@Heavy:~/stm32mp1-baremetal/examples/usb_midi_host$ make
Building startup.s at -O3
Building main.cc at -O3
In file included from midi_host.hh:11,
                 from main.cc:13:
../../shared/drivers/interrupt.hh:14:30: error: 'function' in namespace 'std' does not name a template type
   14 |         using ISRType = std::function<void(void)>;
      |                              ^~~~~~~~
../../shared/drivers/interrupt.hh:4:1: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
    3 | #include <functional>
  +++ |+#include <functional>
    4 |
../../shared/drivers/interrupt.hh:19:35: error: 'ISRType' has not been declared
   19 |         Interrupt(IRQType irqnum, ISRType &&func)
      |                                   ^~~~~~~

Now, <functional> is indeed include in interrupt.hh. I checked. So the header seems to be empty, but that can't be right? So the error message is wrong.

Do you have any idea why this is happening?

Edit: This might be the problem: The compiler is possibly for a freestanding environment.

As of C++20 a compiler for a freestanding environment needs only supply the following headers (from C++20 §complicance/2):

17.2 Types 17.3 Implementation properties , , , 17.4 Integer types 17.5 Start and termination 17.6 Dynamic memory management 17.7 Type identification 17.8 Source location 17.9 Exception handling 17.10 Initializer lists 17.11 Comparisons 17.12 Coroutines support 17.13 Other runtime support Clause 18 Concepts library 20.15 Type traits 26.5 Bit manipulation Clause 31 Atomics

So my question then, would be what now? If that's the case I'm not sure how to move forward.

danngreen commented 4 months ago

I think that's it, it's due to a change in gcc 13 with regards to what "freestanding" means. This came up in another discussion here:

https://github.com/4ms/enosc/issues/1

One solution is, like you found, to use arm gcc v12.x or earlier. Another solution is to remove the -ffreestanding flag. In that other project the only other change needed was to change the signature of main to int main(). I would expect it to be the same fix here.

codewitch-honey-crisis commented 4 months ago

Whoops! Serves me right for not looking through the other issues more carefully. I've been at this for far too long. Imma take a break. Thank you. I got it building and I'm happy for now, and that means hopefully no more bugging you. This is great stuff. I've been trying to use xboot with allwinner A7 based SBCs to achieve similar but I never got anywhere with it. I don't read Chinese very well, so I only got so far. This code is really really fantastic. Breaks through a big wall for me. I owe you a keg of beer. =)