dimanche 22 novembre 2020

Accessing static member function gives: ld: symbol(s) not found for architecture x86_64

I am sure this is a noob C++ question and just reflects my poor understanding.

I have a file

A.cxx contains,

#include "Rishab.h"
#include <future>

void functionToRun() {
  while (true) {
    Rishab::hello();
  }
}

int main() {
    std::future<void> futureVariable = std::async(std::launch::async, functionToRun);
}

Rishab.h

#ifndef __METRIC_RISHAB_H__
#define __METRIC_RISHAB_H__

class Rishab {
public:
    static void hello();

};
#endif

Rishab.cxx

#include "Rishab.h"

void Rishab::hello() {
}

When I try to compile this the linker throws error,

Undefined symbols for architecture x86_64:
  "Rishab::hello()", referenced from:
      functionToRun() in A.cxx.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

PS: These files are a part of a bigger project, so there is a Makefile.

I have gone over other answers online but most of them cater to static variable not being defined (and only declared). But my question involves static function

Aucun commentaire:

Enregistrer un commentaire