Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple Unresolved External Symbol error

Simple Unresolved External Symbol error

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++sharepointvisual-studio
13 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 4705538
    wrote on last edited by
    #1

    Hi, I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:

    1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
    1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)

    In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008 Thanks in advance

    //StringParser.h
    #pragma once

    /////////////////////////////////////////////////////////////////////////////////////////
    //Name: CStringParser
    //Author: Michal Ciechan
    //Date: 2009-06-30
    //Features: A CString parser to parse a string seperated by a
    // character(c) into a vector
    //Usage: call ParseString method with 2 parameters, first being the string
    // etc("Ping&TestPing&value 3") and the second being the seperator
    // etc("&")
    /////////////////////////////////////////////////////////////////////////////////////////

    #include <string>
    #include <vector>
    class CStringParser
    {
    public:
    // Constructor
    CStringParser::CStringParser();
    // Destructor
    CStringParser::~CStringParser();
    // Functions
    std::vector<CString> CStringParser::ParseString(CString s, CString c);
    };

    //StringParser.cpp
    #pragma once
    #include "StringParser.h"
    #include <string>
    #include <vector>

    // Constructor
    CStringParser::CStringParser()
    {
    }
    // Destructor
    CStringParser::~CStringParser()
    {
    }
    //Functions
    std::vector<CString> CStringParser::ParseString(CString s, CString c /*Seperator*/)
    {
    ............
    }

    // Test.h
    #pragma once
    #include "StringParser.h"

    class Test
    {
    public:
    Test(void);
    ~Test(void);
    private:
    CStringParser sp;
    };

    N _ P S A 5 Replies Last reply
    0
    • M Member 4705538

      Hi, I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:

      1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
      1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)

      In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008 Thanks in advance

      //StringParser.h
      #pragma once

      /////////////////////////////////////////////////////////////////////////////////////////
      //Name: CStringParser
      //Author: Michal Ciechan
      //Date: 2009-06-30
      //Features: A CString parser to parse a string seperated by a
      // character(c) into a vector
      //Usage: call ParseString method with 2 parameters, first being the string
      // etc("Ping&TestPing&value 3") and the second being the seperator
      // etc("&")
      /////////////////////////////////////////////////////////////////////////////////////////

      #include <string>
      #include <vector>
      class CStringParser
      {
      public:
      // Constructor
      CStringParser::CStringParser();
      // Destructor
      CStringParser::~CStringParser();
      // Functions
      std::vector<CString> CStringParser::ParseString(CString s, CString c);
      };

      //StringParser.cpp
      #pragma once
      #include "StringParser.h"
      #include <string>
      #include <vector>

      // Constructor
      CStringParser::CStringParser()
      {
      }
      // Destructor
      CStringParser::~CStringParser()
      {
      }
      //Functions
      std::vector<CString> CStringParser::ParseString(CString s, CString c /*Seperator*/)
      {
      ............
      }

      // Test.h
      #pragma once
      #include "StringParser.h"

      class Test
      {
      public:
      Test(void);
      ~Test(void);
      private:
      CStringParser sp;
      };

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Have you added StringParser.cpp to your project?

      Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      1 Reply Last reply
      0
      • M Member 4705538

        Hi, I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:

        1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
        1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)

        In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008 Thanks in advance

        //StringParser.h
        #pragma once

        /////////////////////////////////////////////////////////////////////////////////////////
        //Name: CStringParser
        //Author: Michal Ciechan
        //Date: 2009-06-30
        //Features: A CString parser to parse a string seperated by a
        // character(c) into a vector
        //Usage: call ParseString method with 2 parameters, first being the string
        // etc("Ping&TestPing&value 3") and the second being the seperator
        // etc("&")
        /////////////////////////////////////////////////////////////////////////////////////////

        #include <string>
        #include <vector>
        class CStringParser
        {
        public:
        // Constructor
        CStringParser::CStringParser();
        // Destructor
        CStringParser::~CStringParser();
        // Functions
        std::vector<CString> CStringParser::ParseString(CString s, CString c);
        };

        //StringParser.cpp
        #pragma once
        #include "StringParser.h"
        #include <string>
        #include <vector>

        // Constructor
        CStringParser::CStringParser()
        {
        }
        // Destructor
        CStringParser::~CStringParser()
        {
        }
        //Functions
        std::vector<CString> CStringParser::ParseString(CString s, CString c /*Seperator*/)
        {
        ............
        }

        // Test.h
        #pragma once
        #include "StringParser.h"

        class Test
        {
        public:
        Test(void);
        ~Test(void);
        private:
        CStringParser sp;
        };

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        Member 4705538 wrote:

        Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files.

        What do you mean by previously include .cpp files? Do you mean #include or include in the project? You're most likely not including StringParser.cpp as part of the project. If you don't, this file will not be compiled into an obj file. The linker, when creating the executable will search for the functions(symbols) in the obj files. And since StringParser.obj hasn't been created, it cannot find the constructor and destructor function definitions and so the errors.

        «_Superman_» I love work. It gives me something to do between weekends.

        M 1 Reply Last reply
        0
        • M Member 4705538

          Hi, I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:

          1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
          1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)

          In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008 Thanks in advance

          //StringParser.h
          #pragma once

          /////////////////////////////////////////////////////////////////////////////////////////
          //Name: CStringParser
          //Author: Michal Ciechan
          //Date: 2009-06-30
          //Features: A CString parser to parse a string seperated by a
          // character(c) into a vector
          //Usage: call ParseString method with 2 parameters, first being the string
          // etc("Ping&TestPing&value 3") and the second being the seperator
          // etc("&")
          /////////////////////////////////////////////////////////////////////////////////////////

          #include <string>
          #include <vector>
          class CStringParser
          {
          public:
          // Constructor
          CStringParser::CStringParser();
          // Destructor
          CStringParser::~CStringParser();
          // Functions
          std::vector<CString> CStringParser::ParseString(CString s, CString c);
          };

          //StringParser.cpp
          #pragma once
          #include "StringParser.h"
          #include <string>
          #include <vector>

          // Constructor
          CStringParser::CStringParser()
          {
          }
          // Destructor
          CStringParser::~CStringParser()
          {
          }
          //Functions
          std::vector<CString> CStringParser::ParseString(CString s, CString c /*Seperator*/)
          {
          ............
          }

          // Test.h
          #pragma once
          #include "StringParser.h"

          class Test
          {
          public:
          Test(void);
          ~Test(void);
          private:
          CStringParser sp;
          };

          P Offline
          P Offline
          Pavan_Putra
          wrote on last edited by
          #4

          Try adding file directory of CStringParser in Additional Include directories option.

          It's not enough to be the best, when you have capability to be great....

          C 1 Reply Last reply
          0
          • P Pavan_Putra

            Try adding file directory of CStringParser in Additional Include directories option.

            It's not enough to be the best, when you have capability to be great....

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            Pavan_Putra wrote:

            Try adding file directory of CStringParser in Additional Include directories option

            No, this won't change anything: he has linker errors, not compilation errors. Thus the include are fine.

            Cédric Moonen Software developer
            Charting control [v2.0] OpenGL game tutorial in C++

            1 Reply Last reply
            0
            • M Member 4705538

              Hi, I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:

              1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
              1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)

              In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008 Thanks in advance

              //StringParser.h
              #pragma once

              /////////////////////////////////////////////////////////////////////////////////////////
              //Name: CStringParser
              //Author: Michal Ciechan
              //Date: 2009-06-30
              //Features: A CString parser to parse a string seperated by a
              // character(c) into a vector
              //Usage: call ParseString method with 2 parameters, first being the string
              // etc("Ping&TestPing&value 3") and the second being the seperator
              // etc("&")
              /////////////////////////////////////////////////////////////////////////////////////////

              #include <string>
              #include <vector>
              class CStringParser
              {
              public:
              // Constructor
              CStringParser::CStringParser();
              // Destructor
              CStringParser::~CStringParser();
              // Functions
              std::vector<CString> CStringParser::ParseString(CString s, CString c);
              };

              //StringParser.cpp
              #pragma once
              #include "StringParser.h"
              #include <string>
              #include <vector>

              // Constructor
              CStringParser::CStringParser()
              {
              }
              // Destructor
              CStringParser::~CStringParser()
              {
              }
              //Functions
              std::vector<CString> CStringParser::ParseString(CString s, CString c /*Seperator*/)
              {
              ............
              }

              // Test.h
              #pragma once
              #include "StringParser.h"

              class Test
              {
              public:
              Test(void);
              ~Test(void);
              private:
              CStringParser sp;
              };

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Member 4705538 wrote:

              In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008

              In that case, you either need to a) make a library (static or dynamic, static's probably easier) out of your .cpp file and point your including code at that, or b) wedge all the code from the .cpp file into the .h file (probably not a great idea - don't forget the 'inline' specifiers if you do do that). But...what do you actually mean by 'do it properly using only header files'?

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              M 1 Reply Last reply
              0
              • M Member 4705538

                Hi, I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:

                1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
                1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)

                In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008 Thanks in advance

                //StringParser.h
                #pragma once

                /////////////////////////////////////////////////////////////////////////////////////////
                //Name: CStringParser
                //Author: Michal Ciechan
                //Date: 2009-06-30
                //Features: A CString parser to parse a string seperated by a
                // character(c) into a vector
                //Usage: call ParseString method with 2 parameters, first being the string
                // etc("Ping&TestPing&value 3") and the second being the seperator
                // etc("&")
                /////////////////////////////////////////////////////////////////////////////////////////

                #include <string>
                #include <vector>
                class CStringParser
                {
                public:
                // Constructor
                CStringParser::CStringParser();
                // Destructor
                CStringParser::~CStringParser();
                // Functions
                std::vector<CString> CStringParser::ParseString(CString s, CString c);
                };

                //StringParser.cpp
                #pragma once
                #include "StringParser.h"
                #include <string>
                #include <vector>

                // Constructor
                CStringParser::CStringParser()
                {
                }
                // Destructor
                CStringParser::~CStringParser()
                {
                }
                //Functions
                std::vector<CString> CStringParser::ParseString(CString s, CString c /*Seperator*/)
                {
                ............
                }

                // Test.h
                #pragma once
                #include "StringParser.h"

                class Test
                {
                public:
                Test(void);
                ~Test(void);
                private:
                CStringParser sp;
                };

                A Offline
                A Offline
                Aric Wang
                wrote on last edited by
                #7

                lack of impleation file

                Like C++ more

                1 Reply Last reply
                0
                • _ _Superman_

                  Member 4705538 wrote:

                  Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files.

                  What do you mean by previously include .cpp files? Do you mean #include or include in the project? You're most likely not including StringParser.cpp as part of the project. If you don't, this file will not be compiled into an obj file. The linker, when creating the executable will search for the functions(symbols) in the obj files. And since StringParser.obj hasn't been created, it cannot find the constructor and destructor function definitions and so the errors.

                  «_Superman_» I love work. It gives me something to do between weekends.

                  M Offline
                  M Offline
                  Member 4705538
                  wrote on last edited by
                  #8

                  Thanks for the replies, and yes i haven't included the cpp file into my project, do i just simply include it into any of my files that use the CStringParser or shall i include it in settings or stdafx.h?

                  _ 1 Reply Last reply
                  0
                  • M Member 4705538

                    Thanks for the replies, and yes i haven't included the cpp file into my project, do i just simply include it into any of my files that use the CStringParser or shall i include it in settings or stdafx.h?

                    _ Offline
                    _ Offline
                    _Superman_
                    wrote on last edited by
                    #9

                    Right click on the project name is solutions explorer and select add existing item. Select StringParser.cpp

                    «_Superman_» I love work. It gives me something to do between weekends.

                    M 1 Reply Last reply
                    0
                    • S Stuart Dootson

                      Member 4705538 wrote:

                      In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008

                      In that case, you either need to a) make a library (static or dynamic, static's probably easier) out of your .cpp file and point your including code at that, or b) wedge all the code from the .cpp file into the .h file (probably not a great idea - don't forget the 'inline' specifiers if you do do that). But...what do you actually mean by 'do it properly using only header files'?

                      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                      M Offline
                      M Offline
                      Member 4705538
                      wrote on last edited by
                      #10

                      By properly, i mean when i look at pieces of code, i always only see a something.h, never a something.cpp, in my own code i always had to add the supplier.h to the client.h and the supplier.cpp to the client.cpp, but was wondering if there is a better way of doing it?

                      S 1 Reply Last reply
                      0
                      • M Member 4705538

                        By properly, i mean when i look at pieces of code, i always only see a something.h, never a something.cpp, in my own code i always had to add the supplier.h to the client.h and the supplier.cpp to the client.cpp, but was wondering if there is a better way of doing it?

                        S Offline
                        S Offline
                        Stuart Dootson
                        wrote on last edited by
                        #11

                        Member 4705538 wrote:

                        By properly, i mean when i look at pieces of code, i always only see a something.h, never a something.cpp, in my own code i always had to add the supplier.h to the client.h and the supplier.cpp to the client.cpp, but was wondering if there is a better way of doing it?

                        Short answer - yes, there are better ways of doing it. Longer answer - there are two approaches you could consider. Firstly, as I suggested earlier, make a library (static or dynamic, static's probably easier)[^] out of the supplier.cpp file and get the code that uses it to link against that library. Secondly, you could just add the supplier.cpp file to the Visual Studio project that contains client.cpp. That will automatically include the compiled object files of supplier.cpp and client.cpp in the final executable, which should mean it links and build successfully. HTH!!!

                        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                        1 Reply Last reply
                        0
                        • _ _Superman_

                          Right click on the project name is solutions explorer and select add existing item. Select StringParser.cpp

                          «_Superman_» I love work. It gives me something to do between weekends.

                          M Offline
                          M Offline
                          Member 4705538
                          wrote on last edited by
                          #12

                          Thanks for the quick reply again, i did that but then i got the following errors

                          1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(2) : warning C4627: '#include <string>': skipped when looking for precompiled header use
                          1> Add directive to 'stdafx.h' or rebuild precompiled header
                          1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(3) : warning C4627: '#include <vector>': skipped when looking for precompiled header use
                          1> Add directive to 'stdafx.h' or rebuild precompiled header
                          1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(4) : warning C4627: '#include "CStringParser.h"': skipped when looking for precompiled header use
                          1> Add directive to 'stdafx.h' or rebuild precompiled header
                          1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(48) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

                          I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file, but i was wondering if theres a way of only including the header files or something, but i guess ill stick to my way. Thanks for the replies :)

                          _ 1 Reply Last reply
                          0
                          • M Member 4705538

                            Thanks for the quick reply again, i did that but then i got the following errors

                            1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(2) : warning C4627: '#include <string>': skipped when looking for precompiled header use
                            1> Add directive to 'stdafx.h' or rebuild precompiled header
                            1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(3) : warning C4627: '#include <vector>': skipped when looking for precompiled header use
                            1> Add directive to 'stdafx.h' or rebuild precompiled header
                            1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(4) : warning C4627: '#include "CStringParser.h"': skipped when looking for precompiled header use
                            1> Add directive to 'stdafx.h' or rebuild precompiled header
                            1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(48) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

                            I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file, but i was wondering if theres a way of only including the header files or something, but i guess ill stick to my way. Thanks for the replies :)

                            _ Offline
                            _ Offline
                            _Superman_
                            wrote on last edited by
                            #13

                            Member 4705538 wrote:

                            I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file

                            This is not the right way. Look at the error message. That is what you need to do. Just ensure that #include <stdafx.h> is the first line in all .cpp files. I guess you're missing that in StringParser.cpp.

                            «_Superman_» I love work. It gives me something to do between weekends.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups