Linking to multiple .obj for unit testing a console application

旧时模样 提交于 2019-11-27 20:36:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19496305/linking-to-multiple-obj-for-unit-testing-a-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!