如何解决如何在 premake5 和 VS2019 中使用 googletest
我一直在尝试将 googletest 集成到我的解决方案中,但我遇到了令人讨厌的链接器错误或根本无法添加它。
googletest 作为子模块添加:git submodule add 'https://github.com/google/googletest.git'
一直在尝试像这样配置 premake5:
...
project "libtest"
location "libtest"
kind "ConsoleApp"
language "C++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h","%{prj.name}/src/**.cpp","libtest/vendor/googletest/googletest/**.h","libtest/vendor/googletest/googletest/**.hpp","libtest/vendor/googletest/googletest/src/gtest-all.cc"
}
includedirs
{
"mylib",// DLL
"libtest/vendor/googletest/googletest/include/gtest","libtest/vendor/googletest/googletest/include","libtest/vendor/googletest/googletest"
}
...
然后我得到 LNK2019 unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) libtest C:\dev\mylib\libtest\LIBCMTD.lib(exe_main.obj) 1
解决方法
终于解决了:)
添加一些额外的文件:
int main(int argc,char** argv)
{
testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
修复链接问题,并清理:
"libtest/vendor/googletest/googletest/include/gtest","libtest/vendor/googletest/googletest/include","libtest/vendor/googletest/googletest"
到这里
"libtest/vendor/googletest/googletest/include","libtest/vendor/googletest/googletest/"
足够了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。