Arduino example fails to build, stm32_def.h: No such file or directory

Oof, there is some weirdness going on there. I had to fix two library.json errors in the Portenta H7 AsyncTCP library (Commits · maxgerhardt/Portenta_H7_AsyncTCP · GitHub) and ignored a bunch of non-fitting libraries. PlatformIO’s library dependency finder isn’t yet the best for these extreme cases.

You can use

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
lib_deps =
   khoih-prog/AsyncMQTT_Generic@^1.5.0
   Portenta_H7_AsyncTCP=https://github.com/maxgerhardt/Portenta_H7_AsyncTCP/archive/refs/heads/withdeps.zip
   Ethernet
   SocketWrapper
;lib_compat_mode = strict
lib_ldf_mode = deep+
lib_ignore =
   STM32Ethernet
   STM32duino LwIP
   WiFi
   Teensy41_AsyncTCP
   ESPAsync_WiFiManager
   WebServer_WT32_ETH01
   STM32AsyncTCP
   AsyncTCP_SSL

as the platformio.ini

with src/main.cpp from AsyncMQTT_Generic/FullyFeatured_PortentaH7_Ethernet.ino at main · khoih-prog/AsyncMQTT_Generic · GitHub but with added

#include <Arduino.h>

at the top, and src/defines.h straight from AsyncMQTT_Generic/defines.h at main · khoih-prog/AsyncMQTT_Generic · GitHub.

Which should get you to

Linking .pio\build\portenta_h7_m7\firmware.elf
Checking size .pio\build\portenta_h7_m7\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.1% (used 63136 bytes from 523624 bytes)
Flash: [===       ]  25.3% (used 199200 bytes from 786432 bytes)
Building .pio\build\portenta_h7_m7\firmware.bin
Adding dfu suffix to firmware.bin
dfu-suffix (dfu-util) 0.9

Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Suffix successfully added to file
==============================[SUCCESS] Took 37.07 seconds ==============================[

Edit Simplified platformio.ini, no more build_flags, reordered includes – don’t include Portenta_H7_AsyncTCP.h in src/main.cpp after all.