Jan 3, 2012 at 11:16am Jan 3, 2012 at 11:16am UTC
Hi all,
I've been stuck on this for a while now and haven't find anything relevant on forums...or maybe I just suck at searching...
but here's my little piece of code for which g++ tells me "undefined reference to 'reverse(char const*, char*)'" :
main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include "words.h"
using namespace std;
int main() {
char reversed[9];
reverse("lairepmi" , reversed); //undefined reference to 'reverse(char const*, char*)'
cout << "'lairepmi' reversed is '" << reversed << "'" << endl;
reverse("desserts" , reversed); //undefined reference to 'reverse(char const*, char*)'
cout << "'desserts' reversed is '" << reversed << "'" << endl << endl;
}
words.cpp:
1 2 3 4 5
#include "words.h"
void reverse(const char *str1, char *str2){
cout << "it compiles!" << endl;
}
words.h
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef WORDS_H
#define WORDS_H
#include <iostream>
#include <cstring>
#include <cctype>
#include <fstream>
using namespace std;
void reverse(const char *str1, char *str2);
#endif
the main.cpp file is provided and therefore must not be changed...so the problem definitely doesn't come from there!
I didn't write any code in the function yet as I just want it to compile before I can do anything...Any help would be much appreciated!
Thanks a lot
Last edited on Jan 3, 2012 at 11:17am Jan 3, 2012 at 11:17am UTC
Jan 3, 2012 at 11:18am Jan 3, 2012 at 11:18am UTC
You probably forgot to compile and link words.cpp.
Jan 3, 2012 at 11:34am Jan 3, 2012 at 11:34am UTC
I did forget to link words.cpp...thanks a lot!