collect2: error: ld returned 1 exit status exit status 1 Error compiling.

Hello guys, I’m getting an error, which even with an estensive google search seems to be impossible to solve. I would appreciate if anyone can help.

Apparently Adafruit Fona.h and GSM.h can’t coexist.

Here is the code

#include “Adafruit_FONA.h”
#include <GSM.h>

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

and here is the error

collect2: error: ld returned 1 exit status
exit status 1
Error compiling.

Thank you so much!

What are you using Adafruit_Fona.h for? What kind of hardware do you actually have?

Please post code anderror messagesusing codetags. [code]your code or error here[/code] will result in your code or error here.

Your error message in the output window contains more than likely more information than what you showed. Scroll through the output window and copy / paste the full error message.

Oh ok, thank you.
I’m sending the code within this message because if I include also the error, I exceed the 9000 character restriction

Here is the code

#include "Adafruit_FONA.h"
#include <GSM.h>

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

const int mqx_analogPin=A0;
const int DOUTpin= 8;
const int ledPin= 13;

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
//char sender[20];


int sensorValue; // Code for CO2 sensor

char sendto[21]= "";
char message[141]="CO LEVELS CRITICAL";

// this is a large buffer for replies
char replybuffer[255];

// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines 
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

// Hardware serial is also possible!
//  HardwareSerial *fonaSerial = &Serial1;

// Use this for FONA 800 and 808s
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Use this one for FONA 3G
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
uint8_t type;
void setup() 
{
  while (!Serial);

  Serial.begin(115200);
  pinMode(DOUTpin,INPUT);
  pinMode(ledPin,OUTPUT);
  Serial.println(F("FONA basic test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));
  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) 
  {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  type = fona.type();
  Serial.println(F("FONA is OK"));
  Serial.print(F("Found "));

}

void loop() 
{
  //CODE TO GET AND STORE THE PHONE NUMBER
  char c;
    // If there are any SMSs available()
    if (sms.available())
   {
        Serial.println("Message received from:");

        // Get remote number
        sms.remoteNumber(sendto, 20);
        //the phone number of the sender is stored into char senderNumber and ready to be used
   }


  //BEGIN added code for CO2
  sensorValue = analogRead(0); // read analog input pin 0
  Serial.println(F("CO2 VALUE"));
  Serial.println(sensorValue, DEC); // prints the value read
  delay(100); // wait 100ms for next reading
  
  //END added code for CO2 sensor 
  
  int mqx_value = analogRead(mqx_analogPin);
  int limit = digitalRead(DOUTpin);
  Serial.println(mqx_value);

  if (mqx_value>=90 || sensorValue>=85) //co was 90 and co2 indor was 81 . 85 in car
    {//IF LOOP START
        flushSerial();
        Serial.println(F("CO/CO2 DETECED"));
      //fona.sendSMS(sendto, message);
        if (!fona.sendSMS(sendto, message)) 
        {
          Serial.println(F("Failed"));
        } 
        else 
        {
          Serial.println(F("Sent!"));
  delay(60000);
        }
    }// IF LOOP END
  else
    {
      Serial.println(F("CO/CO2 NOT DETECTED"));
    }
  delay(5000); //delay in milliseconds  

  }

void flushSerial() 
{
  while (Serial.available())
    Serial.read();
}

Here is the error

Arduino: 1.6.7 (Mac OS X), Board: "Arduino/Genuino Uno"

In file included from /Users/andrea/Documents/Arduino/libraries/GSM/src/GSM.h:46:0,
                 from /Users/andrea/Documents/Arduino/sketch_mar30b/sketch_mar30b.ino:2:
/Users/andrea/Documents/Arduino/libraries/GSM/src/GSM3ShieldV1BandManagement.h:49:125: warning: 'typedef' was ignored in this declaration [enabled by default]
 typedef enum GSM3GSMBand {UNDEFINED, EGSM_MODE, DCS_MODE, PCS_MODE, EGSM_DCS_MODE, GSM850_PCS_MODE, GSM850_EGSM_DCS_PCS_MODE};
                                                                                                                             ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'uint8_t Adafruit_FONA::unlockSIM(char*)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:169:16: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
   sendbuff[12] = NULL;
                ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:171:39: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   return sendCheckReply(sendbuff, "OK");
                                       ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'uint8_t Adafruit_FONA::getSIMCCID(char*)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:175:21: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   getReply("AT+CCID");
                     ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'uint8_t Adafruit_FONA::getIMEI(char*)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:194:20: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   getReply("AT+GSN");
                    ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::callPhone(char*)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:353:39: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   return sendCheckReply(sendbuff, "OK");
                                       ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::sendSMS(char*, char*)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:518:41: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (! sendCheckReply("AT+CMGF=1", "OK")) return -1;
                                         ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:518:41: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:524:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (! sendCheckReply(sendcmd, "> ")) return false;
                                     ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::deleteSMS(uint8_t)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:558:43: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     if (! sendCheckReply("AT+CMGF=1", "OK")) return -1;
                                           ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:558:43: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:567:45: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   return sendCheckReply(sendbuff, "OK", 2000);
                                             ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::sendUSSD(char*, char*, uint16_t, uint16_t*)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:573:41: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (! sendCheckReply("AT+CUSD=1", "OK")) return -1;
                                         ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:573:41: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:579:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (! sendCheckReply(sendcmd, "OK")) {
                                     ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::enableGPSNMEA(uint8_t)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:1076:47: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     return sendCheckReply(sendbuff, "OK", 2000);
                                               ^
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA_3G::enableGPRS(boolean)':
/Users/andrea/Documents/Arduino/libraries/Adafruit_FONA/Adafruit_FONA.cpp:1172:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  if (! sendCheckReply(authstring, "OK", 10000))
                                              ^
libraries/GSM/GSM3SoftSerial.cpp.o: In function `__vector_3':
/Users/andrea/Documents/Arduino/libraries/GSM/src/GSM3SoftSerial.cpp:499: multiple definition of `__vector_3'
libraries/SoftwareSerial/SoftwareSerial.cpp.o:/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:229: first defined here
libraries/GSM/GSM3SoftSerial.cpp.o: In function `GSM3SoftSerial::spaceAvailable()':
/Users/andrea/Documents/Arduino/libraries/GSM/src/GSM3SoftSerial.cpp:487: multiple definition of `__vector_4'
libraries/SoftwareSerial/SoftwareSerial.cpp.o:/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:394: first defined here
libraries/GSM/GSM3SoftSerial.cpp.o: In function `GSM3SoftSerial::spaceAvailable()':
/Users/andrea/Documents/Arduino/libraries/GSM/src/GSM3SoftSerial.cpp:487: multiple definition of `__vector_5'
libraries/SoftwareSerial/SoftwareSerial.cpp.o:/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:394: first defined here
collect2: error: ld returned 1 exit status
Multiple libraries were found for "GSM.h"
 Used: /Users/andrea/Documents/Arduino/libraries/GSM
 Not used: /Applications/Arduino.app/Contents/Java/libraries/GSM
exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

From the error message, the conflict is between the GSM library and the SoftwareSerial library. I could not (quickly) find where SoftwareSerial is included.

All the examples that I found in the library on github for the fona board do not include GSM.h but SoftwareSerial.h.

Maybe it's worth a try to adapt your code to use SoftwareSerial.h. Else you have to dig and find where SoftwareSerial is included and probably remove that.

Please answer the questions in Reply #1.

I use Adafruit_fona.h to send text messages.

Here is the hardware: Gsm shield-SIM808 part#:S2-10606-Z1F01 Arduino Uno C02 sensor MG811 C0 sensor MQ-7 Lipo battery-PKCELL LP503562 3.7v 1200mah

I use Adafruit_fona.h to send text messages.

Using?

Gsm shield-SIM808 part#:S2-10606-Z1F01

OK. So, NOT an Arduino GSM shield. So, why are you using the GSM.h library that ONLY works with the Arduino GSM shield?

Arduino to me is very new. I've never used anything like that. As you can imagine I'm confused.

What should I do to fix the problem?

Thank you

What should I do to fix the problem?

Perhaps you could try the Password library. Or maybe the Keypad library. Or some other library that is irrelevant to the hardware that you have.