[英]vcpkg does not work for google test
I installed and integrated latest version of vcpkg:我安装并集成了最新版本的 vcpkg:
e:\work\vcpkg>vcpkg version
Vcpkg package management program version 0.0.65-692a363701156f1bc319306fbde93fb6748325f6
See LICENSE.txt for license information.
e:\work\vcpkg>vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
I installed google test:我安装了谷歌测试:
e:\work\vcpkg>vcpkg list
gtest:x64-windows 1.8 GoogleTest and GoogleMock testing frameworks.
gtest:x86-windows 1.8 GoogleTest and GoogleMock testing frameworks.
I included gtest.h
in my project in Visual Studio 2015 Update 3:我在 Visual Studio 2015 Update 3 的项目中包含了
gtest.h
:
#include <gtest/gtest.h>
It compiles fine, but I have linker errors:它编译得很好,但我有链接器错误:
1>main.obj : error LNK2001: unresolved external symbol "void __cdecl testing::InitGoogleTest(int *,char * *)" (?InitGoogleTest@testing@@YAXPEAHPEAPEAD@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: int __cdecl testing::UnitTest::Run(void)" (?Run@UnitTest@testing@@QEAAHXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static class testing::UnitTest * __cdecl testing::UnitTest::GetInstance(void)" (?GetInstance@UnitTest@testing@@SAPEAV12@XZ)
Apparently, Visual Studio does not know it should link with gtest.lib
.显然,Visual Studio 不知道它应该与
gtest.lib
链接。 And I cannot understand why.我不明白为什么。 Vcpkg only says that "Linking will be handled automatically."
Vcpkg 只说“链接将被自动处理”。 No idea how it is going to do this.
不知道它将如何做到这一点。
In "Additional Library Dependencies" of my project I can see these inherited values:在我的项目的“附加库依赖项”中,我可以看到这些继承的值:
$(VcpkgRoot)lib
$(VcpkgRoot)lib\manual-link
And $(VcpkgRoot)
is resolved to e:\\work\\vcpkg\\installed\\x64-windows\\
.并且
$(VcpkgRoot)
被解析为e:\\work\\vcpkg\\installed\\x64-windows\\
。 So it seems like integration was successful.所以看起来整合是成功的。 But how Visual Studio knows it should link with
gtest.lib
?但是 Visual Studio 如何知道它应该与
gtest.lib
链接?
Note that if I add gtest.lib
to "Additional Dependencies" manually, all works fine, and gtest.dll
is automatically copied to output directory.请注意,如果我手动将
gtest.lib
添加到“附加依赖项”,一切正常,并且gtest.dll
会自动复制到输出目录。
I think that the autolinking behavior has been intentionally disabled for gtest
, see vcpkg issue #306 .我认为
gtest
的自动链接行为已被有意禁用,请参阅vcpkg 问题 #306 。 Original comment on the issue: here .关于这个问题的原始评论: here 。
The vcpkg implementation requires manual linking because Google Test can redefine main()
, and the gtest functionality is duplicated in all of the four separate library files. vcpkg 实现需要手动链接,因为 Google Test 可以重新定义
main()
,并且在所有四个单独的库文件中都重复了 gtest 功能。
Official documentation . 官方文档。
The required per project configuration:每个项目所需的配置:
In: Configuration Properties
> Linker
> Input
> Additional Dependencies
在:
Configuration Properties
> Linker
> Input
> Additional Dependencies
For release-builds:对于发布版本:
$(VcpkgRoot)lib\manual-link\gtest_main.lib
For debug-builds:对于调试版本:
$(VcpkgRoot)debug\lib\manual-link\gtest_main.lib
If you want to create your own custom main(), replace gtest_main.lib
with gtest.lib
.如果要创建自己的自定义 main(),请将
gtest_main.lib
替换为gtest.lib
。
If you want to use gmock, you can replace it with gmock_main.lib
or gmock.lib
.如果你想使用 gmock,你可以用
gmock_main.lib
或gmock.lib
替换它。
This is an old thread but I would like to point out what I've found.这是一个旧线程,但我想指出我发现的内容。
You need to link the libs in the manual-link directory, but you need to link them in the right order.您需要链接 manual-link 目录中的库,但您需要以正确的顺序链接它们。 First link gmock_main then gtest_main.
首先链接 gmock_main 然后 gtest_main。 The other way around just results in 0 test.
反过来只会导致 0 测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.