【问题标题】:ptrdiff_t typedef collision - google-test and intel anacondaptrdiff_t typedef 冲突 - google-test 和 intel anaconda
【发布时间】:2018-06-24 01:11:50
【问题描述】:

上下文

我正在开发一个需要英特尔 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;

我对问题的理解

clang/9.1.0google-testptrdiff_t 上存在 typedef 冲突,其中 google 包含 regex.h,其中包含 conda 自己的 tclInt.h,它具有 typedef。 tclInt.h 由我们需要的 conda intel 频道包安装。卸载它会将mkltbb 降级回各种版本。

这是一个绘制得很糟糕的依赖关系图,它显示了(我认为)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

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.

【问题讨论】:

    标签: c++ gcc cmake clang googletest


    【解决方案1】:

    通常,Tcl 头文件 &lt;tclInt.h&gt; 具有预处理条件,用于确定是应定义 ptrdiff_t 还是应包含 &lt;stddef.h&gt;

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

    但是,英特尔已在其tcl-8.6.4-19.tar.bz2 分发文件中将其修补为:

    #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
    

    可能他们认为他们必须对 _MSC_VER 依赖项做点什么,尽管在这种情况下它是无害的。这适用于 ICC,因为 &lt;stddef.h&gt; 由编译器提供,并且它们的标头版本似乎在定义 _PTRDIFF_T 宏之前对其进行检查。

    通常,这是不可见的,因为在使用tclInt.h 时,您应该使用tclConfig.sh 提供的编译器标志,它定义了STDC_HEADERS,所以&lt;stddef.h&gt; 被无条件使用。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      相关资源
      最近更新 更多