Thread: Overloaded Operator Causes Unresolved External Symbol

  1. #1
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183

    Overloaded Operator Causes Unresolved External Symbol

    Once again I seem to be having unresolved external symbol errors for no reason. Here are the errors:
    Code:
    1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::seekg(long,enum std::ios_base::seekdir)" (__imp_?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@JW4seekdir@ios_base@2@@Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl read(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?read@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
    1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ifstream<char,struct std::char_traits<char> >::open(char const *,int)" (__imp_?open@?$basic_ifstream@DU?$char_traits@D@std@@@std@@QAEXPBDH@Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl read(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?read@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)
    1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::basic_ofstream<char,struct std::char_traits<char> >(char const *,int)" (__imp_??0?$basic_ofstream@DU?$char_traits@D@std@@@std@@QAE@PBDH@Z) referenced in function "bool __cdecl write(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?write@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)
    1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (__imp_??$?6DU?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z) referenced in function "public: bool __thiscall File::Erase(void)" (?Erase@File@@QAE_NXZ)
    1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_ifstream<char,struct std::char_traits<char> >::basic_ifstream<char,struct std::char_traits<char> >(char const *,int)" (__imp_??0?$basic_ifstream@DU?$char_traits@D@std@@@std@@QAE@PBDH@Z) referenced in function "public: bool __thiscall Money_Tracker::Initialize(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct HWND__ *)" (?Initialize@Money_Tracker@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUHWND__@@@Z)
    The problem is stemming from where I use a class and I have an overloaded operator. However, even
    Code:
    cout << "Something or other";
    doesn't work. I've tried reinstalling Visual Studio, and the Platform SDK, but to no avail. Can anyone help me?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Have you tried starting over with a clean project?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    What VS? VS6?
    Have you checked in the Option/Directories
    that Bin/Include/Lib all have Platform SDK paths as a first choice?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    I have tried making a new project, although I'll try again because I may have changed something...
    I have all of the platform SDK paths setup too, and I'm using Visual Studio 2008.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Visual Studio 2008 comes with the platform sdk i believe.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Express does not, but that's irrelevant. These linker errors are against the C++ standard library.

    Could be a mismatch between DLL-linking compiler flags but LIB-linking linker flags. But I have no idea how you'd get there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The problem is stemming from where I use a class and I have an overloaded operator.
    So it works if you remove the class with the overloaded operator? Which operator are you overloading? Is it << or >> ?

  8. #8
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    In fact I'm using both the << and >> operator. Here's the definition for one of the classes:
    Code:
    class Output
    {
    public:
    	int iWindowName;
    	HWND hwnd;
    	Output (void);
    	Output (int windowName, HWND hWnd) {
    		iWindowName = windowName;
    		hwnd = hWnd;
    	}
    	bool operator <<(std::string out);
    	bool operator <<(int out);
    	bool operator <<(double out);
    	Output operator ()(int windowName)
    	{
    		iWindowName = windowName;
    		return *this;
    	}
    	Output operator ()(HWND hWnd, int windowName)
    	{
    		iWindowName = windowName;
    		hwnd = hWnd;
    		return *this;
    	}
    } Cout;
    (This code is for simplifying outputting text to other windows). However, like I mentioned it's not only my class that causes the error.

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Shouldn't operator << return reference to the current instance?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The stream variants, yes, but these are his own overloads, so they can return whatever he wants.

    But this has nothing to do with the linker errors, which are for the standard library streams.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    I just tried the following:
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    
    int main()
    {
    	cout << "hi";
    	return 0;
    }
    And it gives me the following error:
    Code:
    1>Tests.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (__imp_??$?6DU?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z) referenced in function _main
    I have no idea what the problem is, but I'm considering completely removing VC++ from my computer and reinstalling it.

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That sounds like a good idea. It seems like you've picked up some weird project defaults somewhere.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM