Dzyann
Dzyann

Reputation: 5208

How to use classes from a Test project in another Test Project in VC++?

I normally work with C#. In C# I can have a hierarchy, and they reference each other.

I am trying to do the same in VC++, but I dont know how. I don't have much experience with C++ in general.

I have:

I tried adding TestProject1 as reference of TestProject2:

Right Clikc on the TestProject1-> Properties -> Common Properties -> Framework and References -> Add New Reference -> Selected TestProject2

But this results in an error, because TestProject2 is not built as a lib.

From what I can see only a list of obj files are generated.

What is the correct way to reference TestProject2 in TestProject1 so I can use its classes?


Update: How I solved it

I solved the issues by following SOReader instructions, but I added the lib in a different way:

  1. First I changed the TestProject1 project type as SOReader indicated (Right Click on TestProject1 project -> Properties-> Configuration Properties -> General-> Set Configuration Type to Static library (lib)
  2. Add reference to TestProject1 in TestProject2 -> Right Click on TestProject2 project -> Properties-> Common Properties -> Framework and References -> Add New Reference -> Select TestProject1

Upvotes: 1

Views: 146

Answers (1)

SOReader
SOReader

Reputation: 6017

It's not so easy as it is in C#.

You must have TestProject1 build as static library if you want to simply include it to another project. After this you go to dependent project properties and add lib file to linker and headers folder for headers lookup.

enter image description here

enter image description here

enter image description here

Assuming Dll has its include .h file in its root folder (which actually should not have) you simply add an entry to Additional Include Directories to point the place where Dll root folder is.

Now you can just write #include <theheaderfile.h> in you cpp file in Main application to reference exported functionality.

Here are few others locations in msdn that might help: import/export, static libraries, hpp vs h

Upvotes: 1

Related Questions