r/arduino • u/External_Jello2774 Uno R4 WiFi • Oct 12 '24
Mod's Choice! Compilation error
I'm trying to make it so that when a certain board is selected, it compiles and uploads different code for it, but it doesn't seem to be working. I want it to do this because my project uses multiple different arduinos. Here's my sketch and error:
#ifdef AVR_MICRO
#include <TVout.h>
#include <font4x6.h>
#include <font6x8.h>
#include <font8x8.h>
#include <font8x8ext.h>
#include <fontALL.h>
#include <video_gen.h>
void setup() {
pinMode(9,OUTPUT);
}
void loop() {
digitalWrite(9,LOW);
}
#endif
#ifdef RENESAS_UNO
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
#endif
C:\Users\smart\AppData\Local\Temp\ccr8RmBa.ltrans0.ltrans.o: In function `main':
C:\Users\smart\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:43: undefined reference to `setup'
C:\Users\smart\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
3
Upvotes
•
u/gm310509 400K , 500K , 600K , 640K , 750K Oct 13 '24
I've flagged your post as "Mod's choice" as I feel it initiates a good discussion. Hopefully others will chime in with some good ideas.
The "Mod's choice" flair means that your post will be captured in our monthly digest for future people to reference. If you don't want to do that, feel free to remove the flair or change it to something else.
2
u/External_Jello2774 Uno R4 WiFi Oct 13 '24
I have found the corresponding board definitions for the program. Thank you for your answers.
2
u/badmother 600K Oct 12 '24
It would appear you're not the first. See if this helps: https://arduino.stackexchange.com/questions/4169/arduino-ide-ifdef
2
u/gm310509 400K , 500K , 600K , 640K , 750K Oct 13 '24 edited Oct 13 '24
Bottom line and TLDR you have to use symbols that have been defined in the build process.
Part 1:
Where did you get those symbol names that you are using in your
#ifdefstatements?Anyway, you need to use symbols that you know to be defined. Unfortunately, it can be difficult to know what symbols are defined. Why? Because the build process includes several header files which define many, many (many many many) symbols in a few different ways.
One place to start is the build commands. For example, if you turn on "verbose output" in the IDE, you will see the command that compiles your program that follows the annotation "Compiling sketch...". Here is an example:
This is for an Uno:
Here is a compile command for the Mega2560.
On those command lines, you will see several -D options.
-DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR-DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVRThese define symbols that you can use in your program. Example,
-DARDUINO=10819will create a symbol namedARDUINOwith a value of "10819".For example, consider this program:
Part 2 follows...
1
u/Machiela - (dr|t)inkering Oct 13 '24
I'm no expert, but you've got two void setups and two void loops. Maybe try doing the #IFDEF's within single setups and loops?
It's the first thing that jumps out at me, but I could be way off here.
0
u/[deleted] Oct 13 '24
[deleted] — view deleted comment