ptrdiff_t typedef 冲突 - google-test 和 intel anaconda
ptrdiff_t typedef collision - google-test and intel anaconda
上下文
我正在开发一个需要intel的anaconda发行版的项目,我们使用googletest来测试我们的natives。我正在为我的编译器使用 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_t
上 clang/9.1.0
和 google-test
之间存在 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)
我不太确定如何解决这个 typedef 冲突问题并解决它。一种替代方法是使用 gcc-8,但即使我 运行 make
使用导出的环境变量构建 googletest
:
CXX=g++-8
CC=gcc-8
tclInt.h
header 仍然从 clang 文件夹中提取,如我附加的错误转储中所示。
解决方法(?)
肯定还有其他选项是我遗漏的,但是解决这个问题的一种可能方法是 tclInt.h
没有这个问题,或者 gcc-8
有一个一组包含未定义 ptrdiff_t
的 header,我可以做一些事情来指向那个编译器。
注意:我可能错得很离谱,但这是我的假设。任何帮助表示赞赏。
如果有人想查看整个堆栈跟踪,请看这里:
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 header 文件 <tclInt.h>
具有预处理器条件,用于确定是否应定义 ptrdiff_t
或应包含 <stddef.h>
:
#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,因为 <stddef.h>
是由编译器提供的,并且他们的 header 版本似乎在定义它之前检查 _PTRDIFF_T
宏。
通常,这是不可见的,因为在使用 tclInt.h
时,您应该使用 tclConfig.sh
提供的编译器标志,它定义了 STDC_HEADERS
,所以 <stddef.h>
无条件使用。
但是这里使用 Tcl 似乎完全是偶然的,因为 Intel 的 Tcl 发行版包含一个 regex.h
header 覆盖系统 <regex.h>
header,这就是 googletest想包括在这里。使用错误的 header 文件也会导致其他问题。 (这就是为什么其他发行版将 Tcl header 安装在 /usr/include/tcl8.6
等目录中,甚至将内部 header 如 regex.h
放入单独的子目录中。)
我会尝试从构建环境中卸载 Tcl 发行版。希望它不是真正需要的,这样 header 文件冲突就会消失。
上下文
我正在开发一个需要intel的anaconda发行版的项目,我们使用googletest来测试我们的natives。我正在为我的编译器使用 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_t
上 clang/9.1.0
和 google-test
之间存在 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)
我不太确定如何解决这个 typedef 冲突问题并解决它。一种替代方法是使用 gcc-8,但即使我 运行 make
使用导出的环境变量构建 googletest
:
CXX=g++-8
CC=gcc-8
tclInt.h
header 仍然从 clang 文件夹中提取,如我附加的错误转储中所示。
解决方法(?)
肯定还有其他选项是我遗漏的,但是解决这个问题的一种可能方法是 tclInt.h
没有这个问题,或者 gcc-8
有一个一组包含未定义 ptrdiff_t
的 header,我可以做一些事情来指向那个编译器。
注意:我可能错得很离谱,但这是我的假设。任何帮助表示赞赏。
如果有人想查看整个堆栈跟踪,请看这里:
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 header 文件 <tclInt.h>
具有预处理器条件,用于确定是否应定义 ptrdiff_t
或应包含 <stddef.h>
:
#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,因为 <stddef.h>
是由编译器提供的,并且他们的 header 版本似乎在定义它之前检查 _PTRDIFF_T
宏。
通常,这是不可见的,因为在使用 tclInt.h
时,您应该使用 tclConfig.sh
提供的编译器标志,它定义了 STDC_HEADERS
,所以 <stddef.h>
无条件使用。
但是这里使用 Tcl 似乎完全是偶然的,因为 Intel 的 Tcl 发行版包含一个 regex.h
header 覆盖系统 <regex.h>
header,这就是 googletest想包括在这里。使用错误的 header 文件也会导致其他问题。 (这就是为什么其他发行版将 Tcl header 安装在 /usr/include/tcl8.6
等目录中,甚至将内部 header 如 regex.h
放入单独的子目录中。)
我会尝试从构建环境中卸载 Tcl 发行版。希望它不是真正需要的,这样 header 文件冲突就会消失。