CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2015
    Posts
    12

    Linker error with pure virtual function.

    I am making a static library. when I try to use it in an application
    I get following errors in MVS 2013:
    error LNK2001: unresolved external symbol "private: virtual void __thiscall serial::ArduinoMessageParser:arse(class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > >)" (?parse@ArduinoMessageParser@serial@@EAEXV?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
    error LNK2001: unresolved external symbol "private: virtual void __thiscall serial::ArduinoMessageParser:arse(class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > >)" (?parse@ArduinoMessageParser@serial@@EAEXV?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
    error LNK2019: unresolved external symbol "protected: __thiscall serial::AbstractSerialParser::AbstractSerialParser(void)" (??0AbstractSerialParser@serial@@IAE@XZ) referenced in function "public: __thiscall serial::ArduinoMessageParser::ArduinoMessageParser(struct HWND__ *)" (??0ArduinoMessageParser@serial@@QAE@PAUHWND__@@@Z)
    1>E:\Doc\Unterricht\CJ2\SerialComm_Arduino\Debug\ArduinoController.exe : fatal error LNK1120: 2 unresolved externals

    relevant declarations in corresping files neglecting neseccary includes:
    Code:
    	class AbstractSerialParser
    	{
    	protected:
    		virtual void parse(CString s)=0;
    		AbstractSerialParser();
    	public:
    
    		void operator()(const CString &serial_string){ std::thread(&AbstractSerialParser::parse, this, serial_string).detach(); }
    		virtual ~AbstractSerialParser(){};
    	};
    Code:
    class ArduinoMessageParser : public AbstractSerialParser
    	{
    	private:
    		HWND target_window;
    virtual void parse(CString)override;
    		
    	public:
    		
    		ArduinoMessageParser() = delete;
    		ArduinoMessageParser(HWND h) :target_window(h){}
    		ArduinoMessageParser(const ArduinoMessageParser&) = default;
    		~ArduinoMessageParser(){};
    Code:
    void ArduinoMessageParser::parse(CString message)
    	{
    	///implementation for parser
    	}
    I probably miss just a minor detail, but spent a few hours swithout fsuccedding to figure this out

  2. #2
    Join Date
    Dec 2015
    Posts
    2

    Re: Linker error with pure virtual function.

    The error message from the linker refers to "ArduinoMessageParser:arse". Check your code to see if "parse" is misspelled somewhere.

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Linker error with pure virtual function.

    The linker expects both classes to be defined in the namespace 'serial'. From the code you posted, it's not clear if you really defined the classes in this namespace.

  4. #4
    Join Date
    Oct 2008
    Posts
    1,456

    Re: Linker error with pure virtual function.

    Quote Originally Posted by Prandr View Post
    Code:
    void operator()(const CString &serial_string){ std::thread(&AbstractSerialParser::parse, this, serial_string).detach(); }
    as a side note, you're probably using a non-standard implementation of std::thread here ( maybe, vs2013 implemented an early draft ? ) because destroying a detached std::thread will invoke std::terminate()...

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Linker error with pure virtual function.

    Quote Originally Posted by RichardDuNord View Post
    The error message from the linker refers to "ArduinoMessageParser:arse". Check your code to see if "parse" is misspelled somewhere.
    The linker error message as displayed is not shown properly as some of the chars are displayed as an emotive. The correct error message contains
    Code:
    serial::ArduinoMessageParser::Parse(
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Linker error with pure virtual function.

    in
    Code:
    class ArduinoMessageParser : public AbstractSerialParser
    try changing
    Code:
    virtual void parse(CString)override;
    to
    Code:
    virtual void parse(CString s )override;
    any joy?
    ahoodin
    To keep the plot moving, that's why.

  7. #7
    Join Date
    Nov 2015
    Posts
    12

    Re: Linker error with pure virtual function.

    You all gussed wrong.
    What really happened I stepped on the same rake as in the thread http://forums.codeguru.com/showthrea...rtual-function
    this thread could be merged into it

  8. #8
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Linker error with pure virtual function.

    You could have kept that under your hat, but
    maybe your not a self promoter.
    ahoodin
    To keep the plot moving, that's why.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured