如何在 premake5 和 VS2019 中使用 googletest
How to use googletest with premake5 and VS2019
我一直在尝试将 googletest 集成到我的解决方案中,但我要么遇到严重的链接器错误,要么根本无法添加它。
googletest 已添加为子模块:git 子模块添加 '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/"
够了。
我一直在尝试将 googletest 集成到我的解决方案中,但我要么遇到严重的链接器错误,要么根本无法添加它。
googletest 已添加为子模块:git 子模块添加 '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/"
够了。