简体   繁体   中英

Undefined reference to library error in C++

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM