← index #7910PR #18885
Related · medium · value 2.367
QUERY · ISSUE

ports/unix: how to add a c++ shared library to the makefile .i want set a module,which can use c++ function.

openby Mohewkkopened 2021-10-19updated 2024-10-01
port-unix

(no description)

CANDIDATE · PULL REQUEST

multiple ports: Standard approach to Makefile C++ support.

openby projectgusopened 2026-03-03updated 2026-03-26
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.mk is 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 a py/flags.mk or similar and put it there (possibly along with some other things which are the same on all Makefile ports.)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied