0

I'm learning C++, using g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0

I have the following code :

  • main.cpp :
#include <iostream>

void log(std::string message);

int main() {
    log("HI");
}
  • log.cpp :
#include <iostream>

void log(std::string message) 
{
    std::cout << message << std::endl;
}

When i compile and run, i get the following error :

/tmp/ccYckYXk.o: In function `main':
main.cpp:(.text+0x43): undefined reference to `log(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status

Can i please know what's wrong with my code ?

Mohamed Benkedadra
  • 1,964
  • 3
  • 21
  • 48

0 Answers0