0
#include "connection.h"

void setup() {
  Serial.begin(115200);
  Funcs::Connect conn;
  conn.connectWifi();
}

void loop() {

}

then connection.h file:

// connection.h

namespace Funcs
{
  class Connect 
  {
    public:
      void connectWifi();
  };
}

and then connection.cpp

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "connection.h"
const char* ssid     = "ssid";
const char* password = "password";


namespace Funcs
{

  void connectWifi() {
    // Connect to WiFi network
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
      delay(10);
      Serial.print(".");
    }
    Serial.println("");
    Serial.print("WiFi connected with ip ");
    Serial.println(WiFi.localIP());

  }
}

On compiling I get this error:

/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/HardwareSerial.h:76: 
undefined reference to `Funcs::Connect::connectWifi()'

collect2: error: ld returned 1 exit status

collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board WeMos D1 R1.

But I do not have Funcs::Connect::connectWifi() in my code, it was in old code.

1

1 Answer 1

0

You are calling Funcs::Connect::connectWifi() right here:

conn.connectWifi();

since conn is of type Funcs::Connect

But you defined a function Funcs::connectWifi():

namespace Funcs
{

  void connectWifi() {

where I think you meant to have connectWifi be a member of that Connect class.

namespace Funcs
{

  void Connect::connectWifi() {

That's not the only issue with your code, you also create the instance in setup and let it go out of scope after calling just the one function. But that's a different kind of error. It's legal code, just probably doesn't do what you want.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.