0

this code:

#include "SoftwareSerial.h">
#include <avr/io.h>
#include <HardwareSerial.h>
#include <avr/interrupt.h>

void read_response();

int main () {
    sei();
    Serial.begin(2400);
    uint8_t receivePin = 2;
    uint8_t transmitPin = 3;
    SoftwareSerial softSerial(receivePin, transmitPin);
    softSerial.begin(2400);

    while(1){
        softSerial.println("to soft serial");
        Serial.print(softSerial.read());
    }   
}

gives me this error at compile time:

undefined reference to `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)'

I have tried using #include "SoftSerial.h" but no difference. The SoftSerial.h and SoftSerial.cpp files are in my libraries folder where the HardwareSerial.h files also resides.

What am i missing?

4
  • Have you linked with the SoftwareSerial library? Commented Oct 10, 2012 at 14:01
  • 1
    Actually, did you write SoftSerial.cpp yourself? You need to compile it along with your own code. Commented Oct 10, 2012 at 14:02
  • No it's a library which comes with the arduino environment Commented Oct 10, 2012 at 14:04
  • It depends on your environment then. I've not programmed on Arduino so I'm not sure for that specific environment. Commented Oct 10, 2012 at 14:04

1 Answer 1

4

This is not a compile error. This is a linker error.

If SoftSerial is part of your own project, the CPP file is probably not part of the compiled project. If it is an external library, you need to link to it. How you do that depends on your IDE/compiler.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.