Googletest: MSVC 2017 error C2220: warning treated as error - no 'object' file generated

Created on 2 Jan 2018  Â·  5Comments  Â·  Source: google/googletest

git tag: release-1.8.0
configure: cmake 3.10.0
generator: Visual studio 15 2017 Win64

Scenario 1 (gmock)

Errors:

googletest\include\gtest/internal/gtest-port.h(996): error C2220: warning treated as error - no 'object' file generated [build\googlemock\gmock.vcxproj]
googletest\include\gtest/internal/gtest-port.h(996): error C2220: warning treated as error - no 'object' file generated [build\googlemock\gmock_main.vcxproj]
googletest\include\gtest/internal/gtest-port.h(996): error C2220: warning treated as error - no 'object' file generated [build\googletest\gtest.vcxproj]
googletest\include\gtest/internal/gtest-port.h(996): error C2220: warning treated as error - no 'object' file generated [build\googletest\gtest_main.vcxproj]

Scenario 2 (gtest & gtestmain)

Errors:

googletest\include\gtest/internal/gtest-port.h(996): error C2220: warning treated as error - no 'object' file generated [build\googletest\gtest.vcxproj]
googletest\include\gtest/internal/gtest-port.h(996): error C2220: warning treated as error - no 'object' file generated [build\googletest\gtest_main.vcxproj]

Most helpful comment

Actually warning itself (not the error posted above) gives a good clue.
Warning:

googletest\include\gtest\gtest-printers.h(639):
warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED. You can define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to acknowledge that you have received this warning. [build\googlemock\gmock.vcxproj]

So I ran cmake like this and it helped:
cmake ... -DCMAKE_CXX_FLAGS=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING

Although you can get a different warning, then this won't work obviously.
In general to switch off /WX completely you can call like this: cmake ... "-DCMAKE_CXX_FLAGS=/w"

All 5 comments

It would probably be good to disable -Werror or /WX for users of this library – compilers can change, new warnings can be generated. It should still be enabled for your own tests, say on CI or so.

This appears to have been fixed in Visual Studio 15.5.5. https://github.com/google/googletest/commit/718fd88d8f145c63b8cc134cf8fed92743cc112f works well for me.

Is there any simple way (like cmake argument) to skip this error when building release-1.8.0 tag?

Actually warning itself (not the error posted above) gives a good clue.
Warning:

googletest\include\gtest\gtest-printers.h(639):
warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED. You can define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to acknowledge that you have received this warning. [build\googlemock\gmock.vcxproj]

So I ran cmake like this and it helped:
cmake ... -DCMAKE_CXX_FLAGS=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING

Although you can get a different warning, then this won't work obviously.
In general to switch off /WX completely you can call like this: cmake ... "-DCMAKE_CXX_FLAGS=/w"

I have been cleaning up older and inactive GitHub googletest issues. You may see an issue "closed" if it appears to be inactive/abandoned
Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robindegen picture robindegen  Â·  4Comments

markfrazzetto picture markfrazzetto  Â·  3Comments

Joebeazelman picture Joebeazelman  Â·  5Comments

nholthaus picture nholthaus  Â·  6Comments

cyberdecker picture cyberdecker  Â·  3Comments