Can someone help fix this error?

Error Code: /usr/local/bin/arduino-cli compile --fqbn arduino:avr:uno --libraries /home/builder/opt/libraries/latest --build-cache-path /tmp --output-dir /tmp/125229010/build --build-path /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70 /tmp/125229010/sketch_feb7b

Linking everything together...

/home/builder/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70/sketch_feb7b.ino.elf /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70/sketch/sketch_feb7b.ino.cpp.o /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70/../core/core_arduino_avr_uno_f1d675a35cb302d87396e400c56d2f7e.a -L/tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70 -lm

/tmp/ccyfxzbU.ltrans0.ltrans.o: In function `main':

/home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/main.cpp:43: undefined reference to `setup'

/home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/main.cpp:46: undefined reference to `loop'

collect2: error: ld returned 1 exit status

Error during build: exit status 1

Here is the code:

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

char command;

void setup(1) 
{       
 Serial.begin(9600);  //Set the baudrate for Bluetooth module.
}

void loop(1){
 if(Serial.available() > 0){ 
   command = Serial.read(); 
   Stop(); //initialize with motors stoped
   
   //Serial.println(command);
   switch(command){
   case 'F':  
     forward();
     break;
   case 'B':  
      back();
     break;
   case 'L':  
     left();
     break;
   case 'R':
     right();
     break;
   }
 } 
}

void forward()
{
 motor1.setSpeed(255); //Define maximum velocity
 motor1.run(FORWARD); //rotate the motor clockwise
 motor2.setSpeed(255); //Define maximum velocity
 motor2.run(FORWARD); //rotate the motor clockwise
 
 motor3.setSpeed(255); //Define maximum velocity
 motor3.run(FORWARD); //rotate the motor clockwise
 motor4.setSpeed(255); //Define maximum velocity
 motor4.run(FORWARD); //rotate the motor clockwise
}

void back()
{
 motor1.setSpeed(255); 
 motor1.run(BACKWARD); //rotate the motor counterclockwise
 motor2.setSpeed(255); 
 motor2.run(BACKWARD); //rotate the motor counterclockwise

 motor3.setSpeed(255); 
 motor3.run(BACKWARD); //rotate the motor counterclockwise
 motor4.setSpeed(255); 
 motor4.run(BACKWARD); //rotate the motor counterclockwise
}

void left()
{
 motor1.setSpeed(255); //Define maximum velocity
 motor1.run(FORWARD); //rotate the motor clockwise
 motor2.setSpeed(255); //Define maximum velocity
 motor2.run(BACKWARD); //rotate the motor counterclockwise

 motor3.setSpeed(255); //Define maximum velocity
 motor3.run(FORWARD); //rotate the motor clockwise
 motor4.setSpeed(255); //Define maximum velocity
 motor4.run(BACKWARD); //rotate the motor counterclockwise
}

void right()
{
 motor1.setSpeed(255); //Define maximum velocity
 motor1.run(BACKWARD); //rotate the motor counterclockwise
 motor2.setSpeed(255); //Define maximum velocity
 motor2.run(FORWARD); //rotate the motor clockwise

 motor3.setSpeed(255); //Define maximum velocity
 motor3.run(BACKWARD); //turn motor1 off
 motor4.setSpeed(255); //Define maximum velocity
 motor4.run(FORWARD); //rotate the motor clockwise
}

void Stop()
{
 motor1.setSpeed(0);
 motor2.run(RELEASE); //turn motor1 off
 motor2.setSpeed(0);
 motor2.run(RELEASE); //turn motor2 off

 motor3.setSpeed(0);
 motor3.run(RELEASE); //turn motor3 off
 motor4.setSpeed(0);
 motor4.run(RELEASE); //turn motor4 off
}

setup() and loop() do not allow an argument.

How would I fix this?

What is the "1" supposed to do?

Take a look at some of the examples in the Arduino IDE (Files>Examples>...) to see some valid code.

I had it empty there at first and the error still showed up so I just put 1 there as a placeholder.

ok thanks

Unfortunatly, the compiler does not recognise the 1 as a 'placeholder'

Post the original code, and the complete error message for that attempt.

I deleted the 1 and it says undefined reference to setup and loop.

Error Code: /usr/local/bin/arduino-cli compile --fqbn arduino:avr:uno --libraries /home/builder/opt/libraries/latest --build-cache-path /tmp --output-dir /tmp/119831578/build --build-path /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70 /tmp/119831578/sketch_feb7b

Linking everything together...

/home/builder/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70/sketch_feb7b.ino.elf /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70/sketch/sketch_feb7b.ino.cpp.o /tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70/../core/core_arduino_avr_uno_f1d675a35cb302d87396e400c56d2f7e.a -L/tmp/arduino-build-4A14368B1CC0B95AACF0030F65371E70 -lm

/tmp/ccoYvapZ.ltrans0.ltrans.o: In function `main':

/home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/main.cpp:43: undefined reference to `setup'

/home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/main.cpp:46: undefined reference to `loop'

collect2: error: ld returned 1 exit status

Error during build: exit status 1

Code:

#include <AFMotor.h>

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

char command;

void setup() 
{       
 Serial.begin(9600);  //Set the baudrate for Bluetooth module.
}

void loop(){
 if(Serial.available() > 0){ 
   command = Serial.read(); 
   Stop(); //initialize with motors stoped
   
   //Serial.println(command);
   switch(command){
   case 'F':  
     forward();
     break;
   case 'B':  
      back();
     break;
   case 'L':  
     left();
     break;
   case 'R':
     right();
     break;
   }
 } 
}

void forward()
{
 motor1.setSpeed(255); //Define maximum velocity
 motor1.run(FORWARD); //rotate the motor clockwise
 motor2.setSpeed(255); //Define maximum velocity
 motor2.run(FORWARD); //rotate the motor clockwise
 
 motor3.setSpeed(255); //Define maximum velocity
 motor3.run(FORWARD); //rotate the motor clockwise
 motor4.setSpeed(255); //Define maximum velocity
 motor4.run(FORWARD); //rotate the motor clockwise
}

void back()
{
 motor1.setSpeed(255); 
 motor1.run(BACKWARD); //rotate the motor counterclockwise
 motor2.setSpeed(255); 
 motor2.run(BACKWARD); //rotate the motor counterclockwise

 motor3.setSpeed(255); 
 motor3.run(BACKWARD); //rotate the motor counterclockwise
 motor4.setSpeed(255); 
 motor4.run(BACKWARD); //rotate the motor counterclockwise
}

void left()
{
 motor1.setSpeed(255); //Define maximum velocity
 motor1.run(FORWARD); //rotate the motor clockwise
 motor2.setSpeed(255); //Define maximum velocity
 motor2.run(BACKWARD); //rotate the motor counterclockwise

 motor3.setSpeed(255); //Define maximum velocity
 motor3.run(FORWARD); //rotate the motor clockwise
 motor4.setSpeed(255); //Define maximum velocity
 motor4.run(BACKWARD); //rotate the motor counterclockwise
}

void right()
{
 motor1.setSpeed(255); //Define maximum velocity
 motor1.run(BACKWARD); //rotate the motor counterclockwise
 motor2.setSpeed(255); //Define maximum velocity
 motor2.run(FORWARD); //rotate the motor clockwise

 motor3.setSpeed(255); //Define maximum velocity
 motor3.run(BACKWARD); //turn motor1 off
 motor4.setSpeed(255); //Define maximum velocity
 motor4.run(FORWARD); //rotate the motor clockwise
}

void Stop()
{
 motor1.setSpeed(0);
 motor2.run(RELEASE); //turn motor1 off
 motor2.setSpeed(0);
 motor2.run(RELEASE); //turn motor2 off

 motor3.setSpeed(0);
 motor3.run(RELEASE); //turn motor3 off
 motor4.setSpeed(0);
 motor4.run(RELEASE); //turn motor4 off
}

I do not get that error, using the above posted code and compiling with a fresh copy of AFMotor.cpp and AFMotor.h, from the Github site.

Start over, with one of the examples in the AFMotor library, and verify that the example compiles and works as expected.

Try installing a more recent version of the Arduino IDE, too. I used 1.8.19

I'm currently using the Arduino web version, could that be the reason why it's not working?
Heres the link: Arduino Cloud

No idea. I don't use the web version and have no interest in it.

I don't have any reason to think there is something about Arduino Cloud / Arduino Web Editor that would cause this.

I just gave it a try and was not able to reproduce the error. Does it still occur if you try it again now @easton1061?

If yes, I'm going to ask you to post some additional information that might help us to identify the problem.


:exclamation: NOTE: These instructions will not solve the problem. They are only intended to gather more information which might provide a clue that eventually leads to a solution.


Please do this:

  1. From the menu on the left side of the "Arduino Web Editor" window, click "Preferences".
  2. Check the box next to "☐ Always show output panel**".
  3. Check the box next to "☐ Console: Show verbose output**".
  4. In the sketch panel, click the :heavy_check_mark: (verify) button.
  5. After the compilation fails, click the icon in the top right corner of the black console window at the bottom of the "Arduino Web Editor" window that looks like two pieces of paper.
    image
  6. In a forum reply here, click on the reply field.
  7. Click the </> button on the forum toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the compilation output is correctly formatted.
    codetags
  8. Press Ctrl+V.
    This will paste the compilation output between the code tags.
  9. Move the cursor outside of the code tags before you add any additional text to your reply.
  10. Click the Reply button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the Reply button.
  5. Click the "Upload" icon (image) on the post composer toolbar:
    image
  6. Select the .txt file you saved.
  7. Click the Open button.
  8. Click the Reply button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.