2

How to find out all #define used by arduino-cli in compile?

I had seen something some time ago, but I cannot find it again. I think that it was some option somewhere, and the result was that the compile did not end normally, but some generated file contained lots of useful and lots of obscure defined names.

I would like to find everything that's defined in my program, which I want to write, compile, and then run on different Arduinos, but it sometimes need different Serial to be used, different pin assignments, different internal buffer sizes and so on.

And I would like to organize the differences better, than just put all and everything to one big #ifdef - #endif for each extra platform.

Something like:

  • if it does not have Serial but Serial1, #define Serial Serial1
  • if it has 2kB RAM or less, set MY_BUF_SIZE to 10; if it has less than 3kB use 30, else use 100.
  • but if it is Micro Pro, use this pin assignment, else if it is Nano Every use that, else issue error/warning for user, that pins need to be assigned.

And many others...

1
  • 1
    @dda: Thank for your help :) English is my third foreing language and I am still not good at it.
    – gilhad
    Nov 14, 2023 at 20:24

1 Answer 1

3

I am not familiar with arduino-cli. If you can manage to find the g++ command line it uses for compiling your sketch, then you can get the list you are looking for by using a modified version of that command:

  • add the options -E -dM
  • find the option -o output_file and change the name of the output file to something more appropriate.

Edit: Following a suggestion by @gilhad, you can build the required command line by piping the output of arduino-cli through sed:

arduino-cli compile | \
    sed -n '/g++.*\.ino\.cpp\.o/{s/-MMD//;s/-o .*/-E -dM -o defines.dump/;p}'
3
  • Thank you very much - I just made script, that use the make, which normally runs arduino_cli and simply reuse its output: make |grep g++|grep .ino.cpp.o|sed "s/-o .*/-E -dM -o defines.dump/"|sh removed one unneeded file rm defines.d and got defines.dump as result :) You can add this to your answer for better visibility (or I vill make extra answer for that, but in your answer it would fit better)
    – gilhad
    Nov 13, 2023 at 22:25
  • @gilhad: I added this to my answer, with a some modifications: I merged the two grep command into the sed call, and removed the compiler option -MMD in order to prevent the generation of defines.d. Nov 14, 2023 at 12:55
  • Nice, thank you :) I just typed that without thinking much, to try it as soon as possible :) (And to have all the flags and all as near as possible to original build, because my builds are sometimes more complicated)
    – gilhad
    Nov 14, 2023 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.