Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking to multiple .obj for unit testing a console application

Having a few issues and hope I can find some help.

I have two projects under the same solution in Visual Studio 2012

A bit of background I cam creating a console application which outputs as a .exe this is in one project.

In another project I have google test set up to run unit tests on the classes in the console application project.

If I was able to compile the main project into a static library there wouldn't be an issue due to could link to the .lib, however this isn't an option.

I have found that linking to the .obj works however I need to manually enter each one into the linker -> input and due to there is going to be a large number of classes I can see this getting messy.

How do I solve this issue, is there a way of linking to all .obj in the same folder or is there an option I am missing?

like image 736
Chris Crew Avatar asked Oct 21 '13 13:10

Chris Crew


People also ask

How do I link an OBJ file in Visual Studio?

Go to project properties then from "Property Page" select the node "C/C++" their you will get "Additional Include Directories" add the name of your object file. Keep your obj file in the directory where your source code is or you can add the directory from: Tools->Options->Projects and Solutions->VC++Directories .

Does TestInitialize run for each test?

TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no tests are coupled. If you want to run methods before and after ALL tests, decorate relevant methods with the ClassInitialize and ClassCleanup attributes. Save this answer.

How do I run Mstest in Visual Studio?

Test shortcuts Tests can be run from Test Explorer by right-clicking in the code editor on a test and selecting Run test or by using the default Test Explorer shortcuts in Visual Studio.


1 Answers

I had the exact same configuration as yours and this is what I did:

I used the LIB utility of visual studio to put all .obj files into a .lib library, and then I could make my gtest project link to it.

Putting the command

lib /NOLOGO /OUT:"$(TargetPath).lib" "$(ProjectDir)\$(Configuration)\*.obj"

into the "Build events"/"Post-build Event" of your main project, you can keep your console application as a .exe and in the same time aggregate all your obj files to an up-to-date lib.

Hope it helps!

By the way, this problem is a bit similar to this post: Linker error - linking two "application" type projects in order to use Google Test and I think it could be usefull to link it here.

like image 127
toussa Avatar answered Oct 18 '22 22:10

toussa