so i have a function in bunny.cpp, its prototype in the header and i call it in main like so...
here is main.cpp
1 2 3 4 5 6 7 8
#include "iostream"
#include "saystuff.h"
int main ()
{
saystuff ();
return 0;
}
this is saystuff.hvoid saystuff ();
andbunny.cpp
1 2 3 4 5 6 7 8
#include <string>
#include <iostream>
#include "saystuff.h"
void saystuff ()
{
std::cout << "my old mans a dustman";
}
the error is undefined reference to say stuff
I never bothered to learn this while practising but now im making games with sdl it would be nice to build myself a whole library of functions so i could just slot a game together, i watch the online tutorials and i think there is always something they say that i miss.
First the compiler has to compile all the source files separately and then the linker links everything together into a program. The error you have is a linker error.
If you use an IDE make sure that all the files have been added to the project.
If you compile from the command line it will depend on what compiler you use. Using GCC it will look something like this