QUERY · ISSUE
ports/unix: how to add a c++ shared library to the makefile .i want set a module,which can use c++ function.
port-unix
(no description)
CANDIDATE · PULL REQUEST
multiple ports: Standard approach to Makefile C++ support.
port-stm32port-samdpy-coreport-unixport-mimxrtport-renesas-ra
Summary
The goal of this PR is to standardise the approach to building C++ sources in MicroPython ports that use simple Makefiles (esp8266, minimal, mimxrt, renesas-ra, samd, stm32, unix, windows with mingw). This removes a TODO that had been copied into the Makefile of all the bare metal (-nostdlib) ports over the years.
Partially resolves the issues reported in #18351.
Also:
- Adds CI coverage for the example user C modules to esp8266, nrf, mimxrt, renesas-ra & windows mingw ports, meaning all of the ports mentioned above now have CI coverage for building C++ sources. (Except minimal, which isn't built in CI as far as I can tell).
- Fixes C++ compilation on the nrf port.
- Adds a default
abort()implementation to mimxrt port, copied from other ports. This allows the default cppexample module to build. - Explains the libstdc++ dynamic allocation and standard library situation in the docs
Testing
Built with USER_C_MODULES=../../examples/usercmodule and verified the example cppexample module was functional on:
- stm32 port (
BOARD=PYBD_SF2) - samd port (
BOARD=SEEED_WIO_TERMINAL) - unix port (standard variant)
Also built but didn't have hardware to test, but verified the cppfunc symbol appeared in the map file:
- mimxrt port (
BOARD=TEENSY40) - renesas-ra port (
BOARD=EK_RA6M2) - nrf port
CI should also now build at least one board/variants from each of these ports with the usercmodule modules.
Trade-offs and Alternatives
py/mkrules.mkis the most appropriate existing common Makefile I could find for the C++ support, but it doesn't feel 100% right in there to me. We could instead add apy/flags.mkor similar and put it there (possibly along with some other things which are the same on all Makefile ports.)