C++ ptrdiff_t typedef冲突-谷歌测试和英特尔anaconda 上下文

C++ ptrdiff_t typedef冲突-谷歌测试和英特尔anaconda 上下文,c++,gcc,cmake,clang,googletest,C++,Gcc,Cmake,Clang,Googletest,我正在开发一个需要英特尔anaconda发行版的项目,我们使用googletest来测试我们的本地人。我正在为我的编译器使用clang。当我通过cmake构建googletest时,我得到以下信息: 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/

我正在开发一个需要英特尔anaconda发行版的项目,我们使用googletest来测试我们的本地人。我正在为我的编译器使用clang。当我通过
cmake
构建
googletest
时,我得到以下信息:

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;
我对这个问题的理解 在
ptrdiff\u t
上,
clang/9.1.0
googletest
之间存在typedef冲突,其中google包括
regex.h
,其中包括conda自己的
tclInt.h
,后者具有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)
tclInt.h
标题仍然从clang文件夹中提取,如我所附的错误转储中所示

解决方法(?) 我肯定还缺少其他选项,但解决这一问题的一个可能方法是使用一个不存在此问题的
tclInt.h
,或者
gcc-8
有一组包含头,不定义
ptrdiff\u t
,我可以做一些事情来指向该编译器


注:我可能大错特错,但这是我的假设。感谢您的帮助

如果有人想查看整个stacktrace,请点击这里:

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.

通常,Tcl头文件
具有预处理器条件,这些条件决定是应该定义
ptrdiff\u t
还是应该包括

#if defined(STDC_HEADERS) || defined(__STDC__) || defined(__C99__FUNC__) \
     || defined(__cplusplus) || defined(_MSC_VER)
#include <stddef.h>
#else
typedef int ptrdiff_t;
#endif
也许他们认为他们必须对
\u MSC\u VER
依赖性做些什么,尽管在这种情况下它是无害的。这适用于ICC,因为
是由编译器提供的,并且在定义
\PTRDIFF\u T
宏之前,它们的头版本似乎会检查它

通常,这是不可见的,因为在使用
tclInt.h
时,应该使用
tclcconfig.sh
提供的编译器标志,它定义
STDC\u头
,因此无条件使用

但是在这里使用Tcl似乎完全是偶然的,因为Intel的Tcl发行版包含了一个覆盖系统
头的
regex.h
头,而这正是googletest想要包含在这里的内容。使用错误的头文件也会导致其他问题。(这就是为什么其他发行版在目录(如
/usr/include/tcl8.6
)中安装Tcl头,甚至将内部头(如
regex.h
)放在单独的子目录中。)

我将尝试从构建环境中卸载Tcl发行版。希望它不是真的需要,所以头文件冲突消失了

#if defined(STDC_HEADERS) || defined(__STDC__) || defined(__C99__FUNC__) \
     || defined(__cplusplus) || defined(_MSC_VER)
#include <stddef.h>
#else
typedef int ptrdiff_t;
#endif
#ifdef STDC_HEADERS
#include <stddef.h>
#else
#ifdef __ICC
#  ifndef _PTRDIFF_T
#  define _PTRDIFF_T
   typedef int ptrdiff_t;
#  endif
#else
   typedef int ptrdiff_t;
#endif
#endif