简体   繁体   中英

How to use googletest with premake5 and VS2019

I have been trying to integrate googletest into my solution, but I get either nasty linker errors or can't add it at all.

googletest was added as a submodule: git submodule add 'https://github.com/google/googletest.git'

Have been trying configuring premake5 like so:

...
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"
    }
 ...

and I get 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

Finally managed to fix it:)

adding some extra file with:

int main(int argc, char** argv)
{
    testing::InitGoogleTest(&argc, argv);

    return RUN_ALL_TESTS();
}

fixed linking problem, and cleaning up:

"libtest/vendor/googletest/googletest/include/gtest",
"libtest/vendor/googletest/googletest/include",
"libtest/vendor/googletest/googletest"

to this

"libtest/vendor/googletest/googletest/include",
"libtest/vendor/googletest/googletest/"

is enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM