I just installed arvuino-cli on my mac after downloading the latest package following these instructions. I tried to compile my first sketch and the CLI reported the following:
Error during build: fork/exec /bin/avr-g++: no such file or directory
This makes sense because the Arduino GUI installation put everything in ~/Applications. Specifically, the compiler is here:
It took me a day but I finally figured out my problem. Posting solution for posterity...
The compiler location is core dependent. That allows for different boards/processors to use different compilers. You can see these settings (on Mac) in ~/Library/Arduino15/packages/arduino/hardware/*/platform.txt.
'arduino-cli compile' will look up the core of the connected device. If it does not find an installed package it will default to using /bin, where it will not find the compiler. Unfortunately, instead of erroring with "core not installed" the compilation will fail with the above "no such file or directory".
To fix this, be sure you have the right core installed. I had installed arduino:megavr instead of arduino:avr. Once I installed the latter the correct platform.txt was downloaded and my compile succeeded.
pert:
Were you compiling for a board from a 3rd party platform that has a dependency on arduino:avr?
Hi pert thanks for the response. I don't know a lot about what I'm doing but I'd like to help out the project so will provide answers the best I can.
I believe I followed the following sequence:
Connect OSEPP Uno R3 Plus board, which seems to be fully compliant with the Arduino standard.
Add core for arduino:megaavr, which I mistakenly assumed was this board.
Compile (mistakently) for FQBN arduino:megaavr:uno2018.
This produced the no-such-file error for the compiler.
I have since correctly installed core arduino:avr. Compiling to FQBN arduino:avr:uno works fine. If I try to reproduce the original error by compiling to FQBN arduino:megaavr:uno2018 I get the following error:
avrdude: usbhid_open(): No device found
avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2145
Error during Upload: uploading error: exit status 1
I assumed this more descriptive error is appearing because I've since added core arduino:avr. Perhaps the compiler is detecting arduino:avr and using that platform.txt?
Let me know if you'd like me to run any other experiments if that will help.
Connect OSEPP Uno R3 Plus board, which seems to be fully compliant with the Arduino standard.
Most likely. Even if it wasn't, compilation is not affected by the hardware you have (or don't have) connected to your computer. You can compile for boards you don't even own if you like.
If you installed arduino:megaavr and then compiled for one of the arduino:megaavr boards, you definitely shouldn't get that error, even if you never installed arduino:avr.
We do get a lot of reports of the "fork/exec /bin/avr-g++: no such file or directory" type of errors when something goes wrong during the platform installation process that causes the tool to not get installed. The other common cause of this error is that some 3rd party platforms have dependencies on other platforms, so when you install one but not the other then tools are missing, but that's not the case with Arduino's official platforms like arduino:megaavr.
homediggity:
If I try to reproduce the original error by compiling to FQBN arduino:megaavr:uno2018 I get the following error:
avrdude: usbhid_open(): No device found
avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2145
Error during Upload: uploading error: exit status 1
I guess you're using arduino-cli compile --upload? It's expected that the upload will fail if you don't have an Arduino Uno WiFi Rev2 connected to your computer. If you omit the --upload flag from the command then the compilation will be successful.
homediggity:
Let me know if you'd like me to run any other experiments if that will help.
Thanks for the offer! Since you've already fixed the problem, there isn't much we can do to investigate it. For now, I think we should just be glad that everything is working as expected. Feel free to post on the forum if you run into other problems.
pert:
I guess you're using arduino-cli compile --upload? It's expected that the upload will fail if you don't have an Arduino Uno WiFi Rev2 connected to your computer. If you omit the --upload flag from the command then the compilation will be successful.
My makefile (really just a zsh build script) runs arduino-cli upload after arduino-cli compile. That error came from the upload command which ran after a successful compile. As you said, compiling to the wrong target is not an error, per se. It just produces a binary that will fail later.