I have the following in header file.
namespace silc{
class pattern_token_map
{
/* Contents */
};
pattern_token_map* load_from_file(const char*);
}
In the CPP file (this has got proper includes)
pattern_token_map* load_from_file(const char* filename)
{
// Implementation goes here
}
In another CPP file. This has got all proper includes.
void some_method()
{
const char* filename = "sample.xml";
pattern_token_map* map = load_from_file( filename ); // Linker complains about this.
}
I am getting a linker error saying that undefined reference to load_from_file. I am not able to see what is going wrong here.
Any help would be appreciated.
Compiler : G++
OS : Ubuntu 9.10
Edit
Here is the linker command used.
g++ -L/home/nkn/silc-project/third_party/UnitTest++ -o tests.out src/phonetic_kit/pattern_token_map.o tests/pattern_token_map_tests.o tests/main.o -lUnitTest++
Error is from pattern_token_map_tests.o and the function is available in pattern_token_map.o. So I guess the order of linking is not making the problem. (I have removed some files from the command to simplify it)
When you implement it, you have to make sure you implement the right function:
If you instead did this:
Then you’d be defining a new function rather than silc::load_from_file.
Avoid using directives (“using namespace …;”) outside of function scope, as a general guideline: