Контекст
Я занимаюсь разработкой проекта, который требует дистрибутива Intel Anaconda, и мы используем googletest для тестирования наших нативных пользователей. Я использую Clang для моего компилятора. Когда я строю googletest
через cmake
, я получаю это:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-all.cc:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/gtest.h:58:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-internal.h:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-port.h:452:
In file included from /foo/anaconda3/envs/idp3/include/regex.h:4:
/foo/anaconda3/envs/idp3/include/tclInt.h:60:16: error: typedef redefinition with different types
('int' vs 'long')
typedef int ptrdiff_t;
Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stddef.h:51:26: note: previous definition is here
typedef __PTRDIFF_TYPE__ ptrdiff_t;
Мое понимание проблемы
Между clang/9.1.0
и google-test
на ptrdiff_t
произошла коллизия typedef, где Google включает regex.h
, который включает собственный tclInt.h
от conda, который имеет typedef. tclInt.h
устанавливается необходимыми пакетами каналов conda intel. При удалении он понижает mkl
и tbb
до различных версий.
Вот плохо нарисованный график зависимостей, который показывает, где (я думаю) произошел typdef:
project native tests <-- googletest <-- regex.h <-- tclInt.h "typedef ptrdiff_t int;"
^
|
stddef.h "typedef ptrdiff_t long" (from clang)
Я не совсем уверен, как подойти к этой проблеме столкновения typedef и распутать ее. Один из вариантов - использовать gcc-8, но даже если я запускаю make
для сборки googletest
с экспортированными переменными env:
CXX=g++-8
CC=gcc-8
заголовок tclInt.h
все еще извлекается из папки clang, как указано в дампе ошибок, который я прикрепил.
Способы ее решения (?)
Определенно есть и другие варианты, которые мне не хватает, но возможный способ решить эту проблему - иметь tclInt.h
, у которого нет этой проблемы, или, возможно, gcc-8
имеет набор заголовков включения, которые не имеют не определить ptrdiff_t
, и я могу кое-что сделать, чтобы указать на этот компилятор.
Примечание: я могу быть совершенно неправ, но это моя гипотеза. Любая помощь приветствуется.
Если кто-то хочет увидеть всю трассировку стека, то вы идете:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-all.cc:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/gtest.h:58:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-internal.h:39:
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/include/gtest/internal/gtest-port.h:452:
In file included from /foo/anaconda3/envs/idp3/include/regex.h:4:
/foo/anaconda3/envs/idp3/include/tclInt.h:60:16: error: typedef redefinition with different types ('int' vs 'long')
typedef int ptrdiff_t;
^
/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stddef.h:51:26: note: previous definition is here
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^
In file included from /foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-all.cc:45:
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:597:10: error: use of undeclared identifier 'regexec'
return regexec(&re.full_regex_, str, 1, &match, 0) == 0;
^
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:606:10: error: use of undeclared identifier 'regexec'
return regexec(&re.partial_regex_, str, 1, &match, 0) == 0;
^
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:619:15: error: use of undeclared identifier 'regcomp'
is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
^
/foo/home/bar/native/build/gradle_unittest_build/googletest-src/googletest/src/gtest-port.cc:630:17: error: use of undeclared identifier 'regcomp'
is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
^
5 errors generated.