LNK2019: unresolved external symbol

Hi

I'm new in C++. Can anybody explain why one of the following projects doesn't compile??

http://www.filedropper.com/cpptest

Thank you!!
.cpp files aren't (shouldn't be) included ever, so they don't need include guards...
This line: TEST::MyStaticClass msc; where did this come from? There is no class in the TEST namespace called MyStaticClass.
TEST:MyStaticClass comes from the other dll (CppTest). Out of this dll I included a header file...:

#include "../CppTest/MyStaticClass.h"

Now I thought I could use it...:

1
2
3
4
5
6
7
8
9
10
11
12
namespace TEST
{

//c'tor, d'tor

void MyUnitTest::Test()
{
	TEST::MyStaticClass msc;
	//do stuff
}

}


It seems like I didn't properly link CppTest... Obviously "include" itself is not sufficient. What else do I have to do?
Including the header gives you the definition of the class, but all the functions only have declarations and are not defined. The cpp file has all the definitions - you'll have to figure out how you want to solve this problem (do not include the cpp file!)
Thank you for helping me!!

Coming from C# I would do the following:

- add reference to CppTest
- add using TEST; on top of MyUnitTest.cs file (not even necessary)

Therefore I tried the following in C++:

- add reference to CppTest
- add #include "../CppTest/MyStaticClass.h" on top of MyUnitTest.cpp

Unfortunately this doesn't work...

As you can see CppTest itself compiles... I now just want to add some unit test. I created a new project and now I just want to use MyStaticClass which is defined in CppTest. Do I have to add CppTest to the linker-dependencies??
If you want to make the class reusable, you should define its functions inline.
?? Sorry, I think I get lost...

CppTest is an ordinary library... (it should be at least)
In CppUnitTest I want to test CppTest...

Where do I have to define functions inline? In CppTest??
It's not a library or a DLL, you're including a header file as if it were part of your project. Here is an example of a class with inline functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class MyClass
{
  int value;
public:
  MyClass() : value(0) {}
  MyClass(const int &from) : value(from) {}
  MyClass(const MyClass &from) : value(from.value) {}

  void SetValue(const int& from)
  {//Notice that I implement the functions in the class definition
    value = from;
  }
  int GetValue()
  {
    return(value);
  }

  ~MyClass(){}
};


If you convert your MyStaticClass to a class with all inlined functions, it will be completely reusable without the need for a partner cpp file.
Last edited on
I see...

Does this mean that I have to get rid of MyStaticClass.cpp and put all the stuff in MyStaticClass.h instead?
If you want the class to be able to be used without needing a cpp file to go with it, yes.
OK, I also found another solution which is probably basically the same:

1
2
3
4
5
#if defined(XYZLIBRARY_EXPORT) // inside DLL
#   define XYZAPI   __declspec(dllexport)
#else // outside DLL
#   define XYZAPI   __declspec(dllimport)
#endif  // XYZLIBRARY_EXPORT 


and then extend my class like:
class XYZAPI MyStaticClass

This allows me to keep my .cpp and .h files... (I don't know if that's an advantage though...)
Topic archived. No new replies allowed.