googletest icon indicating copy to clipboard operation
googletest copied to clipboard

when operating “CMake compile and VS2022 Debug build”, meets VS “LNK1107 invalid or corrupt file: cannot read at 0x378” and "gmock_mainpdb_debug_postfix-NOTFOUND.pdb" creates in file systems

Open congmingyige opened this issue 3 years ago • 4 comments

Problem: when operating “CMake compile and VS2022 Debug build”, meets VS “LNK1107 invalid or corrupt file: cannot read at 0x378” and "gmock_mainpdb_debug_postfix-NOTFOUND.pdb" creates in file systems

Environment: Win10

Process: 1 CMake Choose VS2022, x64 Untitled CMakeCache.txt

2 VS output:

Build started...
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>Checking Build System
2>------ Build started: Project: gtest, Configuration: Debug x64 ------
3>------ Build started: Project: gmock_main, Configuration: Debug x64 ------
4>------ Build started: Project: gmock, Configuration: Debug x64 ------
2>Building Custom Rule D:/software/c++_library/googletest/googletest/CMakeLists.txt
2>gtest-all.cc
3>Building Custom Rule D:/software/c++_library/googletest/googlemock/CMakeLists.txt
4>Building Custom Rule D:/software/c++_library/googletest/googlemock/CMakeLists.txt
3>gtest-all.cc
4>gtest-all.cc
3>gmock-all.cc
4>gmock-all.cc
2>   Creating library D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gtest.lib and object D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gtest.exp
3>gmock_main.cc
4>Generating Code...
2>gtest.vcxproj -> D:\software\c++_library\googletest\build\VS2022_x64_Debug\bin\Debug\gtest.dll
3>Generating Code...
5>------ Build started: Project: gtest_main, Configuration: Debug x64 ------
5>Building Custom Rule D:/software/c++_library/googletest/googletest/CMakeLists.txt
4>   Creating library D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gmock.lib and object D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gmock.exp
5>gtest_main.cc
4>gmock.vcxproj -> D:\software\c++_library\googletest\build\VS2022_x64_Debug\bin\Debug\gmock.dll
3>   Creating library D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gmock_main.lib and object D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gmock_main.exp
3>gmock_main.vcxproj -> D:\software\c++_library\googletest\build\VS2022_x64_Debug\bin\Debug\gmock_main.dll
5>   Creating library D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gtest_main.lib and object D:/software/c++_library/googletest/build/VS2022_x64_Debug/lib/Debug/gtest_main.exp
5>gtest_main.vcxproj -> D:\software\c++_library\googletest\build\VS2022_x64_Debug\bin\Debug\gtest_main.dll
6>------ Build started: Project: ALL_BUILD, Configuration: Debug x64 ------
6>Building Custom Rule D:/software/c++_library/googletest/CMakeLists.txt
========== Build: 6 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

File in Path:

 Directory of D:\software\c++_library\googletest\build\VS2022_x64_Debug\bin\Debug

2022/05/24  16:36    <DIR>          .
2022/05/24  16:36    <DIR>          ..
2022/05/24  16:36         1,411,584 gmock.dll
2022/05/24  16:36         8,622,080 gmockpdb_debug_postfix-NOTFOUND.pdb
2022/05/24  16:36         1,413,120 gmock_main.dll
2022/05/24  16:36         8,671,232 gmock_mainpdb_debug_postfix-NOTFOUND.pdb
2022/05/24  16:36         1,148,416 gtest.dll
2022/05/24  16:36         7,147,520 gtestpdb_debug_postfix-NOTFOUND.pdb
2022/05/24  16:36           206,336 gtest_main.dll
2022/05/24  16:36         2,682,880 gtest_mainpdb_debug_postfix-NOTFOUND.pdb
  1. VS runs cpp files 1

cpp files has #include <gtest/gtest.h>

  1. build using Release If use Release, no xxx.pdb creates)

Problem: Untitled

cpp

#include <gtest/gtest.h>

TEST(a,b) {
	EXPECT_EQ(1, 1);
	EXPECT_TRUE(true);

}

int main()
{
    //testing::InitGoogleTest();
    //testing::FLAGS_gtest_filter="";
    //testing::FLAGS_gtest_filter=testing::FLAGS_gtest_filter + ":TestFuncBasic.*";
    return RUN_ALL_TESTS();
}
  1. Others a. If use VS2019, this problem also happens. b. If not use build_gmock, this problem also happens. c. If not use build_share_libs, no dll files creates.

congmingyige avatar May 24 '22 08:05 congmingyige

Please completely fill out the bug template at https://github.com/google/googletest/blob/main/.github/ISSUE_TEMPLATE/00-bug_report.md to help us reproduce this more easily. If you have a commandline only reproduction that would be helpful.

derekmauro avatar Jun 06 '22 19:06 derekmauro

I'm seeing the NOTFOUND issue as well when building on Windows. It may be related to the following commit: https://github.com/google/googletest/commit/ca3ffd90f2726f6c0c6e790f05c7c88491a16466

The following code seems to expect the property to exist: https://github.com/google/googletest/blob/7735334a46da480a749945c0f645155d90d73855/googletest/cmake/internal_utils.cmake#L168

A workaround is to define CMAKE_DEBUG_PREFIX to nothing when invoking CMake.

balagansky avatar Sep 09 '22 22:09 balagansky

For those like myself who fear CMake, as @balagansky suggests, something like cmake . -G "Visual Studio 17 2022" -A x64 -D gtest_force_shared_crt=ON -D CMAKE_DEBUG_PREFIX="" will do the trick

ncook-hxgn avatar Apr 24 '23 14:04 ncook-hxgn