链接到多个.obj用于单元测试控制台应用程序 [英] Linking to multiple .obj for unit testing a console application

查看:98
本文介绍了链接到多个.obj用于单元测试控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个问题,希望我能找到一些帮助。

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

我在Visual Studio 2012中有两个项目在同一个解决方案下

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

有一点背景我创建一个控制台应用程序,作为一个.exe输出在一个项目中。

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

在另一个项目中,我有google测试设置为在控制台应用程序项目中的类上运行单元测试。

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

如果我能够将主项目编译成静态库,则不会有问题,因为可以链接到.lib,但这不是一个选项。

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.

我发现链接到.obj的工作,但我需要手动输入每个一个进入链接器 - >输入,由于会有大量的类,我可以看到这变得凌乱。

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.

如何解决这个问题,有一种方法可以链接到同一个文件夹中的所有.obj,或者有一个我缺少的选项?

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?

推荐答案

完全与您的配置相同,这是我做的:

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

我使用visual studio的LIB工具将所有.obj文件放入.lib库,然后我可以让我的gtest项目链接到它。

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.

放置命令

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

添加到主项目的Build events/Post-build Event中,您可以将控制台应用程序保存为.exe,同时将所有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.

希望它有帮助!

顺便说一句,这个问题是一个位类似于此信息:链接器错误 - 链接两个应用程序类型的项目,以使用Google测试,我认为这可能是有用的链接到这里。

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.

这篇关于链接到多个.obj用于单元测试控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆