I have the need to include a function defined in an r.cpp file in another called a.cpp, I tried the following:
In the r.cpp file:
#include "r.h"
void lee(){
cout<<" Hola "<<endl;
}
In the r.h file:
#ifndef R_H
#define R_H
void leer();
#endif
In the a.cpp file:
#include <iostream>
#include "r.h"
using namespace std;
int main(){
lee();
return 0;
}
Compiled in the console as follows:
g++ a.cpp
But I threw the following error:
/tmp/ccFRVxGt.o: In function
main': a.cpp:(.text+0x5f): undefined reference to
reads () 'collect2: error: ld returned 1 exit status
How could I solve it?