How to solve GTest and LibTorch linkage conflict

This question follows my precedent one on StackOverflow.

I’m writing a C++ program with OpenCV, Torch and NumCpp. The program compiles and works fine for now, but I need to write unit tests.

I’ve followed google’s tutorial to build GTest and GMock inside my project, but it fails. When I don’t link Torch libraries, that works.

Error when linking GTest + Torch :

/usr/bin/ld: CMakeFiles/TryGTest_test.dir/test/boxTest.cpp.o: in function `testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&)':
/tmp/tmp.Z1zXnMtLsD/cmake-build-debug-ubuntu_2/googletest-src/googletest/include/gtest/gtest.h:1511: undefined reference to `testing::internal::EqFailure(char const*, char const*, std::string const&, std::string const&, bool)'
collect2: error: ld returned 1 exit status

I suppose it comes from Libtorch defining macros with the same name as Gtest, and Google proposes a workaround at the end of the linked tutorial to fix this type of problem, but I need to find which macro is failing.

Hope someone can help me finding libtorch macro names :slight_smile: