#1 2015-02-12 21:24:32

Oodin
Учасник
Зареєстрований: 2015-02-12
Повідомлень: 7

Помогите устранить ошибку компиляции

Arduino: 1.5.8 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\1288~1\AppData\Local\Temp\build5737123430700990464.tmp/core.a(main.cpp.o): In function `main':
D:\arduino-1.0.6\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:34: undefined reference to `setup'
collect2: error: ld returned 1 exit status
Помогите разобраться, что это за ошибка и как ее устранить.

Неактивний

#2 2015-02-12 21:49:41

Ярослав
Гість

Re: Помогите устранить ошибку компиляции

Наведіть, будь ласка, Ваш код.

#3 2015-02-12 23:44:38

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: Помогите устранить ошибку компиляции

см тут http://en.wikiversity.org/wiki/Arduino_ … e_Tutorial

Step Three: Write New Setup And Loop Functions[edit]
Save the sketch and click compile again. The next lot of error messages you get will say:-

core.a(main.cpp.o): In function `main': /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:11: undefined reference to `setup' /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:14: undefined reference to `loop'

Just to make them more unreadable, they will be split up, but lets take them one at a time:- The first line says In function `main':, What! we don't have a function called main in our sketch so what is it on about? Well main is a function that is hidden by the Arduino interface, one that it puts in itself. In that function it calls a function called setup() once and then repeatedly calls a function called loop(). It expects to find these two functions in your sketch, there used to be one, well actually two, but we renamed them both and now there aren't any. So lets add some, type this at the start of the sketch.

/* Fade Blink

an exercise in combining code
*/
void setup(){
  setupFade();
  setupBlink();
}

void loop(){
   loopFade();
   loopBlink();
}
Save and compile again and this time no errors!!!

However, a word of caution, just because the compiler knows how to handle what you wrote it doesn't mean it makes sense, or it will do what you think. It's like a spell checker, you can have a completely correctly spelled essay, but if the words are not the right ones and in the right order a reader will not be able to understand it.

в будушем рекомендую давать более подробную информацию )
типа - написал а оно не компилируется, или работало а тут такая штука. 
волшебников тут почти нет ) угадывать некому,

может Вы просто удалили void setup()

если проект небольшой , начните с нуля,  добавляя ваш код  по частям, если это возможно.


пока смотрел код выложили,
мне не понравилось Setup() , вроде везде с маленькой пишут)

Остання редакція NoName (2015-02-12 23:48:10)

Неактивний

#4 2015-02-13 00:05:13

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: Помогите устранить ошибку компиляции

с удовольствием почитал комментарии,
но не увидел watchdog (, к таким штукам желательно аппаратный и програмный watchdog  прикручивать.
но право его использовать  только ваше

Неактивний

#5 2015-02-13 13:53:38

Андрей
Учасник
Зареєстрований: 2014-06-17
Повідомлень: 46

Re: Помогите устранить ошибку компиляции

Да, это из-за Setup С большой буквы

Неактивний

#6 2015-11-25 21:09:39

Sender1993
Гість

Re: Помогите устранить ошибку компиляции

помогите не  компилируется! Вот код // works also with ATMEGA8 — tested
// SPI PINS used for transfer from CDCemulator to RADIO:
// MOSI (arduino pin 11) -> DataIN
// CLK (arduino pin 13) -> CLK

#include <spi.h>
//#include <softwareserial.h>

#define PREV 9 //PB1,pin 15
#define PLAY 5 //PD5, pin 11
#define NEXT 6 //PD6,pin 12
#define DataOut 2
#define BUFFER 10

#define BYTES_DELAY 750//874
#define PACKET_DALEY 100

#ifdef DataOut==2
#define Data_out_interrupt 0
#elif DataOut==3
#define Data_out_interrupt 1
#endif

#define CDC_PREFIX1 0x53
#define CDC_PREFIX2 0x2C

#define CDC_END_CMD 0x14
#define CDC_END_CMD2 0x38
#define CDC_PLAY 0xE4
#define CDC_STOP 0x10
#define CDC_NEXT 0xF8
#define CDC_PREV 0x78
#define CDC_SEEK_FWD 0xD8
#define CDC_SEEK_RWD 0x58
#define cd1 0x0C
#define cd2 0x8C
#define cd3 0x4C
#define cd4 0xCC
#define cd5 0x2C
#define cd6 0xAC
#define CDC_SCAN 0xA0
#define CDC_SFL 0x60
#define CDC_PLAY_NORMAL 0x08

#define MODE_PLAY 0xFF
#define MODE_SHFFL 0x55
#define MODE_SCAN 0x00

volatile uint16_t captimehi = 0;
volatile uint16_t captimelo = 0;
volatile uint8_t capturingstart = 0;
volatile uint8_t capturingbytes = 0;
volatile uint32_t cmd[BUFFER];
volatile uint8_t cmd_write_buffer_pointer = 0;
volatile uint8_t cmd_read_buffer_pointer = 0;
volatile uint8_t cmdbit = 0;
volatile uint8_t newcmd[BUFFER];
volatile uint8_t prev_cmd = 0;

volatile uint8_t cd=0xBE;
volatile uint8_t tr=0xFE;
volatile uint8_t mode=MODE_PLAY;
volatile uint8_t idle=1;
volatile uint8_t load_cd=0;

uint8_t getCommand(uint32_t cmd2);
void send_package(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5, uint8_t c6, uint8_t c7);
void read_Data_out();
void prev_song();
void toggle_play_mode();
void next_song();
void play_cd(uint8_t cd);

void setup(){
pinMode(PREV, OUTPUT);
pinMode(PLAY, OUTPUT);
pinMode(NEXT, OUTPUT);
digitalWrite(PREV, LOW);
digitalWrite(PLAY, LOW);
digitalWrite(NEXT, LOW);

pinMode(DataOut, INPUT_PULLUP);
attachInterrupt(Data_out_interrupt, read_Data_out, CHANGE);
cli();//stop interrupts
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0;
// Set CS11 bit for 8 => tick every 1us@8MHz, 0.5us@16MHz
// Set CS11 bit and CS10 for 64 prescaler => tick every 8us@8MHz, 4us@16MHz
TCCR1B |= (1 << CS11);//| (1 << CS10);
sei();//allow interrupts
// Serial.begin(115200);
// Serial.println("start");
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV128); //62.5kHz@8Mhz 125kHz@16MHz
//SPI.setClockDivider(SPI_CLOCK_DIV64);//125kHz@8Mhz

send_package(0x34,cd, tr,0xFF,0xFF, mode,0xFA,0x3C); //load disc
delay(100);
send_package(0x74,cd, tr,0xFF,0xFF, mode,0x8F,0x7C); //idle
delay(10);
}

void loop(){
for(int cmd_read_buffer_poiter=0;cmd_read_buffer_poiter<buffer;cmd_read_buffer_poiter++)
{
if(newcmd[cmd_read_buffer_poiter])
{
// tmp_cmd=getCommand(cmd);
// Serial.println(cmd[cmd_read_buffer_poiter], HEX);
switch(getCommand(cmd[cmd_read_buffer_pointer]))
{
case CDC_STOP:
prev_cmd=CDC_STOP;
break;
case CDC_PLAY_NORMAL:
prev_cmd=CDC_PLAY_NORMAL;
break;
case CDC_PLAY:
prev_cmd=CDC_PLAY;
break;
case CDC_PREV:
prev_cmd=CDC_PREV;
break;
case CDC_NEXT:
prev_cmd=CDC_NEXT;
break;
case cd1:
prev_cmd=cd1;
break;
case cd2:
prev_cmd=cd2;
break;
case cd3:
prev_cmd=cd3;
break;
case cd4:
prev_cmd=cd4;
break;
case cd5:
prev_cmd=cd5;
break;
case cd6:
prev_cmd=cd6;
break;
case CDC_END_CMD:
if (prev_cmd==CDC_PLAY_NORMAL || prev_cmd==CDC_PLAY)
{
idle=0;
mode = MODE_PLAY;
toggle_play_mode();
}
else if (prev_cmd==CDC_PREV)
{
idle=0;
tr++;
prev_song();
}
else if (prev_cmd==CDC_NEXT)
{
idle=0;
tr--;
next_song();
}
else if (prev_cmd==CDC_STOP)
{
idle=1;
toggle_play_mode();
}
prev_cmd=0;
break;
case CDC_END_CMD2:
if (prev_cmd==cd1)
{
idle=0;
cd = 0xBE;
play_cd(cd);
}
else if (prev_cmd==cd2)
{
idle=0;
cd = 0xBD;
play_cd(cd);
}
else if (prev_cmd==cd3)
{
idle=0;
cd = 0xBC;
play_cd(cd);
}
else if (prev_cmd==cd4)
{
idle=0;
cd = 0xBB;
play_cd(cd);
}
else if (prev_cmd==cd5)
{
idle=0;
cd = 0xBA;
play_cd(cd);
}
else if (prev_cmd==cd6)
{
idle=0;
cd = 0xB9;
play_cd(cd);
}
prev_cmd=0;
break;
}
newcmd[cmd_read_buffer_poiter]=0;
// Serial.print("CD: ");
// Serial.print(cd, HEX);
// Serial.print(" TR: ");
// Serial.print(tr, HEX);
// Serial.print(" mode: ");
// Serial.print(mode, HEX);
// Serial.print(" idle: ");
// Serial.println(idle);
}
}

if(idle){
send_package(0x74,cd, tr,0xFF,0xFF, mode,0x8F,0x7C);
}
else
{
send_package(0x34,cd, tr,0xFF,0xFF, mode,0xCF,0x7c);
}
delay(PACKET_DALEY);

}

uint8_t getCommand(uint32_t cmd2)
{
if (((cmd2>>24) & 0xFF) == CDC_PREFIX1 && ((cmd2>>16) & 0xFF) == CDC_PREFIX2)
if (((cmd2>>8) & 0xFF) == (0xFF^((cmd2) & 0xFF)))
return (cmd2>>8) & 0xFF;
return 0;
}

void send_package(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5, uint8_t c6, uint8_t c7)
{
SPI.transfer(0x34);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(c1);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(c2);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(c3);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(c4);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(c5);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(0xCF);
delayMicroseconds(BYTES_DELAY);
SPI.transfer(c7);
}

void read_Data_out() //remote signals
{
//if (newcmd==0){
if(digitalRead(DataOut))
{
if (capturingstart || capturingbytes)
{
captimelo = TCNT1;
}
else
capturingstart = 1;
TCNT1 = 0;

//eval times
//tick @0.5us
//9000us HIGH and 4500us LOW
if (captimehi > 17000 && captimelo > 8000 )//&& captimehi < 19000/8 && captimelo < 10000)
{
capturingstart = 0;
capturingbytes = 1;
// cmdbit=0;
// cmd=0;
//Serial.println("startseq found");
} //logic one = 1700us
else if(capturingbytes && captimelo > 3300 )//&& captimelo < 3500)
{
//Serial.println("bit 1");
cmd[cmd_write_buffer_pointer] = (cmd[cmd_write_buffer_pointer]<<1) | 0x00000001;
cmdbit++;
}
else if (capturingbytes && captimelo > 1000)// && captimelo < 1200)
{
//Serial.println("bit 0");
cmd[cmd_write_buffer_pointer] = (cmd[cmd_write_buffer_pointer]<<1);
cmdbit++;
}

if(cmdbit == 32)
{
//Serial.println("32bit");
//Serial.println(cmd[cmd_write_buffer_poiter], HEX);
newcmd[cmd_write_buffer_pointer] = 1;
capturingbytes = 0;
cmdbit=0;
cmd_write_buffer_pointer++;
if(cmd_write_buffer_pointer==BUFFER) cmd_write_buffer_pointer=0;
}
}
else
{
captimehi = TCNT1;
TCNT1 = 0;
}
// }
}

void prev_song()
{
digitalWrite(PREV, HIGH);
delay(100);
digitalWrite(PREV, LOW);
delay(25);
digitalWrite(PREV, HIGH);
delay(100);
digitalWrite(PREV, LOW);
}
void toggle_play_mode()
{
digitalWrite(PLAY, HIGH);
delay(100);
digitalWrite(PLAY, LOW);
}
void next_song()
{
digitalWrite(NEXT, HIGH);
delay(100);
digitalWrite(NEXT, LOW);
}

void play_cd(uint8_t cd)
{
toggle_play_mode();
}

#7 2015-11-27 18:27:31

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: Помогите устранить ошибку компиляции

Sender1993, привет, такая  ошибка?

fatal error: spi.h: No such file or directory

Неактивний

#8 2015-11-29 01:37:27

epilandrus
Учасник
Зареєстрований: 2015-11-29
Повідомлень: 0

Re: Помогите устранить ошибку компиляции

Хочу сделать "светофор": 3 LED, которые при каждом нажатии кнопки загораются по очереди. С функция ми слабо знаком. Что-то не получается:

int active_color=9;
void setup() {
pinMode(6, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
 

int SwitchState=0;
int button;

SwitchState=digitalRead(6);
if (SwitchState==HIGH)
  {change_lights(active_color);
}
  if (active_color==12){(active_color=9);}
   active_color++;
}
void change_lights(active_color) {
 
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(active_color, HIGH);

}

Неактивний

#9 2015-11-30 10:56:43

vvr
Учасник
Зареєстрований: 2015-04-12
Повідомлень: 875

Re: Помогите устранить ошибку компиляции

Скачай и установи библиотеку OneButton (борьба с дребезгом).
Кнопка подключается между пином и землёй.




#include "OneButton.h"

#define ButtonPin   6
#define LED_1       9
#define LED_2       10
#define LED_3       11

OneButton button(ButtonPin, true);
int state = 0;

void setup()

  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);
  button.attachClick(Click);
}

void loop()
{
  button.tick();

  if(state == 0)
  {
    digitalWrite(LED_1, LOW);
    digitalWrite(LED_2, LOW);
    digitalWrite(LED_3, LOW);
  }
  if(state == 1)
  {
    digitalWrite(LED_1, HIGH);
    digitalWrite(LED_2, LOW);
    digitalWrite(LED_3, LOW);
  }
  if(state == 2)
  {
    digitalWrite(LED_1, LOW);
    digitalWrite(LED_2, HIGH);
    digitalWrite(LED_3, LOW);
  }
  if(state == 3)
  {
    digitalWrite(LED_1, LOW);
    digitalWrite(LED_2, LOW);
    digitalWrite(LED_3, HIGH);
  }
}

void Click()
{
  state ++;
  if(state > 3)
    state = 0;
}

Неактивний

#10 2015-12-06 15:03:56

epilandrus
Учасник
Зареєстрований: 2015-11-29
Повідомлень: 0

Re: Помогите устранить ошибку компиляции

vvr пише:

Скачай и установи библиотеку OneButton (борьба с дребезгом).

Спасибо!
А можно оформить этот набор команд в виде функции? Или в Arduino удобнее использовать библиотеки?
Просто хочу ребенка научить программированию и сам по ходу что-то вспоминаю ,что-то новое узнаю.
Функция, она как бы очевиднее

Неактивний

#11 2015-12-06 15:04:06

epilandrus
Учасник
Зареєстрований: 2015-11-29
Повідомлень: 0

Re: Помогите устранить ошибку компиляции

vvr пише:

Скачай и установи библиотеку OneButton (борьба с дребезгом).

Спасибо!
А можно оформить этот набор команд в виде функции? Или в Arduino удобнее использовать библиотеки?
Просто хочу ребенка научить программированию и сам по ходу что-то вспоминаю ,что-то новое узнаю.
Функция, она как бы очевиднее

Неактивний

#12 2018-01-05 19:04:58

Vadim
Гість

Re: Помогите устранить ошибку компиляции

Доброе время суток подскажите ,у меня поблема при компилирование выдаёт exit status 1 arduino nano,шо это значит ?  вот пример #include "DHT.h"
#define DHTPIN 2
DHT dht(DHTPIN, DHT22);
//DHT dht(DHTPIN, DHT11);
void setup()
{
  Serial.begin(9600);
  dht.begin();
}
void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Ошибка считывания");
    return;
  }
  Serial.print("Влажность: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Температура: ");
  Serial.print(t);
  Serial.println(" *C ");
}
(заранее благодарен за ответ)

#13 2018-01-05 20:10:04

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: Помогите устранить ошибку компиляции

дайте полный лог
exit status 1 это ошибка компиляции.

Неактивний

Швидке повідомлення

Введіть повідомлення і натисніть Надіслати

Підвал форуму