vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Cannot build googletest example using MSYS2 and cmake-tools

Open ToBoMi opened this issue 2 years ago • 1 comments

Brief Issue Summary

Building the googletest example from googletest: Quickstart: Building with CMake in Visual Studio Code using cmake-tools and MSYS2 on Windows 10 fails.

Notes: It succeeds from the MSYS2 MinGW64 terminal. It succeeds with cmake-tools when I select a Windows (VS Studio) toolchain instead of MSYS2.

(Maybe this is more a question on how to get it build with cmake-tools or if cmake-tools is intended to work with MSYS2)

Prerequisites:

Reproduction steps:

  1. Put MSYS2 MinGW64 directory on (user) path. (See also issue https://github.com/microsoft/vscode-cmake-tools/issues/2447)
  2. Start VS Code
  3. Create the source files and cmake files according to the example mentioned above
  4. Start configuration in cmake-tools using the toolchain detected by cmake-tools: GCC [...]
  5. Build the project using cmake-tools

Build failes with:


[...]

[build] [10/10 100% :: 13.728] Linking CXX executable hello_test.exe
[build] FAILED: hello_test.exe hello_test[1]_tests.cmake C:/swdev/googletestExampleVisualStudioCode/build/hello_test[1]_tests.cmake 
[build] cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe -g  CMakeFiles/hello_test.dir/hello_test.cc.obj -o hello_test.exe -Wl,--out-implib,libhello_test.dll.a -Wl,--major-image-version,0,--minor-image-version,0  lib/libgtest_main.a  lib/libgtest.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cmd.exe /C "cd /D C:\swdev\googletestExampleVisualStudioCode\build && C:\msys64\mingw64\bin\cmake.exe -D TEST_TARGET=hello_test -D TEST_EXECUTABLE=C:/swdev/googletestExampleVisualStudioCode/build/hello_test.exe -D TEST_EXECUTOR= -D TEST_WORKING_DIR=C:/swdev/googletestExampleVisualStudioCode/build -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_FILTER= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=hello_test_TESTS -D CTEST_FILE=C:/swdev/googletestExampleVisualStudioCode/build/hello_test[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -D TEST_XML_OUTPUT_DIR= -P C:/msys64/mingw64/share/cmake-3.22/Modules/GoogleTestAddTests.cmake""
[build] CMake Error at C:/msys64/mingw64/share/cmake-3.22/Modules/GoogleTestAddTests.cmake:83 (message):
[build]   Error running test executable.
[build] 
[build]     Path: 'C:/swdev/googletestExampleVisualStudioCode/build/hello_test.exe'
[build]     Result: Exit code 0xc0000139
[build] 
[build]   
[build] 
[build]     Output:
[build]       
[build] 
[build] Call Stack (most recent call first):
[build]   C:/msys64/mingw64/share/cmake-3.22/Modules/GoogleTestAddTests.cmake:179 (gtest_discover_tests_impl)
[build] 
[build] 
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.65.2",
  "cmtVersion": "1.10.5",
  "configurations": [
    {
      "folder": "c:\\swdev\\googletestExampleVisualStudioCode",
      "cmakeVersion": "3.22.2",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "C:/msys64/mingw64/bin/gcc.exe",
        "CXX": "C:/msys64/mingw64/bin/g++.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 5,
    "executablesCount": 1,
    "librariesCount": 4,
    "targets": [
      {
        "name": "hello_test",
        "type": "EXECUTABLE"
      },
      {
        "name": "gmock",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "gmock_main",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "gtest",
        "type": "STATIC_LIBRARY"
      },
      {
        "name": "gtest_main",
        "type": "STATIC_LIBRARY"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

[main] Building folder: googletestExampleVisualStudioCode 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build all
[proc] Executing command: C:\msys64\mingw64\bin\cmake.EXE --build c:/swdev/googletestExampleVisualStudioCode/build --config Debug --target all --
[build] [5/10  10% :: 1.448] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
[build] [5/10  20% :: 1.498] Building CXX object CMakeFiles/hello_test.dir/hello_test.cc.obj
[build] [5/10  30% :: 1.647] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj
[build] [5/10  40% :: 2.952] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.obj
[build] [5/10  50% :: 7.825] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
[build] [6/10  60% :: 9.898] Linking CXX static library lib\libgtest.a
[build] [8/10  70% :: 10.024] Linking CXX static library lib\libgtest_main.a
[build] [9/10  80% :: 10.238] Linking CXX static library lib\libgmock.a
[build] [10/10  90% :: 10.345] Linking CXX static library lib\libgmock_main.a
[build] [10/10 100% :: 13.415] Linking CXX executable hello_test.exe
[build] FAILED: hello_test.exe hello_test[1]_tests.cmake C:/swdev/googletestExampleVisualStudioCode/build/hello_test[1]_tests.cmake 
[build] cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe -g  CMakeFiles/hello_test.dir/hello_test.cc.obj -o hello_test.exe -Wl,--out-implib,libhello_test.dll.a -Wl,--major-image-version,0,--minor-image-version,0  lib/libgtest_main.a  lib/libgtest.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cmd.exe /C "cd /D C:\swdev\googletestExampleVisualStudioCode\build && C:\msys64\mingw64\bin\cmake.exe -D TEST_TARGET=hello_test -D TEST_EXECUTABLE=C:/swdev/googletestExampleVisualStudioCode/build/hello_test.exe -D TEST_EXECUTOR= -D TEST_WORKING_DIR=C:/swdev/googletestExampleVisualStudioCode/build -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_FILTER= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=hello_test_TESTS -D CTEST_FILE=C:/swdev/googletestExampleVisualStudioCode/build/hello_test[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -D TEST_XML_OUTPUT_DIR= -P C:/msys64/mingw64/share/cmake-3.22/Modules/GoogleTestAddTests.cmake""
[build] CMake Error at C:/msys64/mingw64/share/cmake-3.22/Modules/GoogleTestAddTests.cmake:83 (message):
[build]   Error running test executable.
[build] 
[build]     Path: 'C:/swdev/googletestExampleVisualStudioCode/build/hello_test.exe'
[build]     Result: Exit code 0xc0000139
[build] 
[build]   
[build] 
[build]     Output:
[build]       
[build] 
[build] Call Stack (most recent call first):
[build]   C:/msys64/mingw64/share/cmake-3.22/Modules/GoogleTestAddTests.cmake:179 (gtest_discover_tests_impl)
[build] 
[build] 
[build] ninja: build stopped: subcommand failed.
[cmakefileapi-parser] Read reply folder: c:\swdev\googletestExampleVisualStudioCode\build\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-f00e53a8721923f38460.json","codemodel-v2-fde9bc76c1e4419e2e1e.json","directory-.-Debug-d0094a50bb2071803777.json","directory-_deps.googletest-build-Debug-8b187651187085369010.json","directory-_deps.googletest-build.googlemock-Debug-219f8951a82f9b159b85.json","directory-_deps.googletest-build.googletest-Debug-891949a46de799d7a5cc.json","index-2022-03-23T09-35-31-0095.json","target-gmock-Debug-1b59d74ffd354f86abe8.json","target-gmock_main-Debug-85e69065e441a7293260.json","target-gtest-Debug-f233732b97ff66fa79dc.json","target-gtest_main-Debug-0260e6c264e1ed39d538.json","target-hello_test-Debug-bfa45ce0dbf6bfed5d22.json","toolchains-v1-f8f5ecbc2541b3aeec33.json"]
[build] Build finished with exit code 1
[cache] Reading CMake cache file c:/swdev/googletestExampleVisualStudioCode/build/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [3876] cmake.buildAll finished (returned 1)

ToBoMi avatar Mar 23 '22 09:03 ToBoMi