How do I get hex files to store in same directory as the sketch?

I am using Arduino IDE 2.3.6 for Windows. I want a hex file for each compiled sketch but it stores it in the default sketchbook folder which is never where I am working. If I change the default sketchbook folder then it can not find the installed libraries.

I find it to be very strange behavior on the part of the IDE that it does not store the hex file in the same directory as the sketch itself!

How do I get it to store the exported hex file in the same directory as the sketch itself and not somewhere that is hard to find and get to?

Thank you.

Which board are you compiling for?

When I export (board used is an Arduino Micro) I get a build directory

C:\USERS\BUGGE\ONEDRIVE\DOCUMENTS\ARDUINO\1_FORUM.ARDUINO.CC\_xxx\1399875_xxx\1399875_POST13_RS485SLAVE_01
|   1399875_post13_rs485slave_01.ino
|
\---build
    \---arduino.avr.micro
            1399875_post13_rs485slave_01.ino.eep
            1399875_post13_rs485slave_01.ino.elf
            1399875_post13_rs485slave_01.ino.hex
            1399875_post13_rs485slave_01.ino.lst
            1399875_post13_rs485slave_01.ino.with_bootloader.bin
            1399875_post13_rs485slave_01.ino.with_bootloader.hex
1 Like

Uno

Yes the build directory is in the default sketchbook directory and not in the directory where I am actually working.

No, it's in the sketch directory. Your "sketchbook folder" did put me on the wrong foot.

I'm not sure if it can be done. I think that this is one for the specialist.

If it can be changed, it will be in the file platforms.txt; on my Windows system C:\Users\bugge\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\platform.txt

Information about that file: https://docs.arduino.cc/arduino-cli/platform-specification/#platformtxt. From that:

The hooks might be useful for what you want to achieve.