簡體   English   中英

ptrdiff_t typedef collision - google-test和intel anaconda

[英]ptrdiff_t typedef collision - google-test and intel anaconda

上下文

我正在開發一個需要intel的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_tclang/9.1.0google-test之間存在typedef沖突,其中google包含regex.h ,其中包括regex.h自己的tclInt.h ,其中包含typedef。 tclInt.h由我們需要的tclInt.h 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來構建帶有導出的env變量的googletest

CXX=g++-8
CC=gcc-8

仍然從clang文件夾中提取tclInt.h標頭,如我附加的錯誤轉儲中所示。

解決方法(?)

我肯定還有其他選項,但是解決這個問題的可能方法是讓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.

通常,Tcl頭文件<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>由編譯器提供,並且它們的標題版本在定義之前會出現以檢查_PTRDIFF_T宏。

通常情況下,因為使用時,這是不可見tclInt.h ,你應該使用所提供的編譯器標志tclConfig.sh ,它定義STDC_HEADERS ,所以<stddef.h>無條件地使用。

但是這里使用Tcl似乎完全是偶然的,因為英特爾的Tcl發行版包含了一個regex.h標題,它覆蓋了系統<regex.h>標題,這就是googletest想要包含的內容。 使用錯誤的頭文件也會導致其他問題。 (這就是為什么其他發行版在諸如/usr/include/tcl8.6目錄中安裝Tcl頭文件,甚至將內部頭文件如regex.h放入一個單獨的子目錄中的原因。)

我會嘗試從構建環境中卸載Tcl發行版。 希望它不是真的需要,因此頭文件沖突消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM