reference to unresolved external symbol error while using COR/DOR

Here is a piece of my code
1
2
3
4
5
6
7
8
9
10
11
class FDatasource : public BDatasource 
{
public:
//constructor
FDatasource(std::string sFilename,unsigned int uiBlocklength,
                   bool Loop=false);
//destructor	
virtual ~FDatasource();

/* declarations of member variables and functions etc etc */
};


In main() I initialise an object as follows:
FDatasource ob1("Guitar.wav",128,false);

When I build , I get the following errors:

1>....obj : error LNK2019: Reference to unresolved external symbol ""public: virtual __thiscall FDatasource::~FDatasource(void)" (??1FDatasource@@UAE@XZ)" in Funktion "_wmain".
1>....obj : error LNK2019: Reference to unresolved external symbol ""public: __thiscall FDatasource::FDatasource(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,unsigned int,bool)" in Funktion "_wmain".

1>.... .exe : fatal error LNK1120: 2 unresolved externals.

What is the problem with my initialisation?
PS: if the problem is elsewhere I would be more than happy to share more of my code.




Last edited on
It looks a bit like you have not defined your constructor and destructor.

Actually: The above piece of code is in a .h file. Now the definition is in a .cpp file.Here it is:

1
2
3
4
5
6
7
8
9
10
FDatasource::FDatasource(std::string sFilename,
			        unsigned int uiBlocklength,
        bool bLoopMode) : BDatasource(uiBlocklength)
         {  /* lots of computation  */ }

         FDatasource::~FDatasource() 
       {
	     /*  appropriate delete stuff     */
        }       
 


So in short the CTOR/DTOR declaration is in a .h file. And the definition is in a corresponding .cpp file. So now what do I do, put them or together? Or what do you all suggest?

Last edited on
You need a third file which contains your main function. You will have to ensure that when your main function gets linked into an executable that the object file *.o from your class's .cpp file is included in the link.

If you are using an IDE that might mean adding your .cpp file to the project. If you are using the command line then that would be compiler dependant.

For GCC it would be something like this:


g++ -o myprog my_class.cpp main.cpp
I do hope that you're compiling both files, not just one or the other.

Oh... is there anything else in that header file?

EDIT: Wow, two posts that said almost the same thing separated by no more than a minute.

-Albatross
Last edited on
Thanks a lot!! BTW Im working in Visual studio 2005.

@Galik : Yep my main function is in a 3rd file main.cpp

I have the .obj file of the corresponding file FDatasource.cpp; in which folder should I include it so that main.cpp runs?


PS:For some reason , in the main.cpp project window only the .h file is visible , not the .cpp file; even though I have copied both the files in the same folder. Thats why I guess only the .h file was compiling all the time.


@Albatross no nothing else in the header file.
souptik wrote:
PS:For some reason , in the main.cpp project window only the .h file is visible , not the .cpp file; even though I have copied both the files in the same folder. Thats why I guess only the .h file was compiling all the time.


That sounds like it may be your problem.

There should be some way of adding the .cpp file to your project. Putting it in the same folder may not be enough. Perhaps look under the Project menu if you have one? Or select the file in the IDE file viewer, get a right-click menu and there may be the option to "add to project" from there.

Different IDEs have different ways.
Last edited on
Topic archived. No new replies allowed.