![](/img/trans.png)
[英]Does vcpkg still work on macOS since new M series laptops?
[英]vcpkg does not work for google test
我安裝並集成了最新版本的 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.
我安裝了谷歌測試:
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.
我在 Visual Studio 2015 Update 3 的項目中包含了gtest.h
:
#include <gtest/gtest.h>
它編譯得很好,但我有鏈接器錯誤:
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)
顯然,Visual Studio 不知道它應該與gtest.lib
鏈接。 我不明白為什么。 Vcpkg 只說“鏈接將被自動處理”。 不知道它將如何做到這一點。
在我的項目的“附加庫依賴項”中,我可以看到這些繼承的值:
$(VcpkgRoot)lib
$(VcpkgRoot)lib\manual-link
並且$(VcpkgRoot)
被解析為e:\\work\\vcpkg\\installed\\x64-windows\\
。 所以看起來整合是成功的。 但是 Visual Studio 如何知道它應該與gtest.lib
鏈接?
請注意,如果我手動將gtest.lib
添加到“附加依賴項”,一切正常,並且gtest.dll
會自動復制到輸出目錄。
我認為gtest
的自動鏈接行為已被有意禁用,請參閱vcpkg 問題 #306 。 關於這個問題的原始評論: here 。
vcpkg 實現需要手動鏈接,因為 Google Test 可以重新定義main()
,並且在所有四個單獨的庫文件中都重復了 gtest 功能。
官方文檔。
每個項目所需的配置:
在: Configuration Properties
> Linker
> Input
> Additional Dependencies
對於發布版本:
$(VcpkgRoot)lib\manual-link\gtest_main.lib
對於調試版本:
$(VcpkgRoot)debug\lib\manual-link\gtest_main.lib
如果要創建自己的自定義 main(),請將gtest_main.lib
替換為gtest.lib
。
如果你想使用 gmock,你可以用gmock_main.lib
或gmock.lib
替換它。
這是一個舊線程,但我想指出我發現的內容。
您需要鏈接 manual-link 目錄中的庫,但您需要以正確的順序鏈接它們。 首先鏈接 gmock_main 然后 gtest_main。 反過來只會導致 0 測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.