Simple Unresolved External Symbol error
-
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;
}; -
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;
};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
-
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;
};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.
-
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;
};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....
-
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....
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++ -
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;
};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
-
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;
}; -
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.
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?
-
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?
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.
-
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
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?
-
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?
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
-
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.
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 :)
-
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 :)
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.