2016-01-13 34 views
5

使用VS 2015及其新內置的clang工具集/項目模板,我無法成功構建Google測試。我收到以下錯誤:無法使用Visual Studio 2015和Clang 3.7與Microsoft CodeGen一起構建Google測試

Error  use of undeclared identifier 'chdir'; did you mean '_chdir'?  
Error  use of undeclared identifier 'fdopen' 
Error  use of undeclared identifier 'read' 
Error  use of undeclared identifier 'write'  
Error  use of undeclared identifier 'close' 
Error  use of undeclared identifier 'O_RDONLY' 
Error  use of undeclared identifier 'O_APPEND' 
Error  use of undeclared identifier 'dup'; did you mean '_dup'? 
Error  use of undeclared identifier 'creat'; did you mean '_creat'? 

我注意到,大多數這些聲明的是這些ANSI檢查街區:

#if !__STDC__ 
... 
#endif 

是否有一個項目設置什麼的,我可以改變,以獲得這些方法解決?

回答

1

我遇到了chdir和freopen類似的問題。

我只會發布我採取的步驟,讓googletest與VS2015和Clang一起運行。

  • 獲取windows的LLVM snapshotbuild。 http://llvm.org/builds/
    (請確保您下載正確的版本(32位/ 64位))

這將安裝最新的鐺的版本(在撰寫V3.9的時間)。請注意,這是一個快照構建,而不是正式版本。

如果你不喜歡快照構建,也許嘗試最新的發行版本。我沒有測試它。我只想擁有最新的工具,特別是當他們像LLVM/Clang一樣快節奏時。

  • 安裝完成後,您應該可以在Visual Studio項目屬性中獲取條目。 Properties - >General - >Platform Tools - >LLVM-vs2014(及以上) (切換到LLVM-vs2014

我知道你所要求的3.7鏘與微軟的CodeGen。你必須自己決定。
另外,我不喜歡對我沒有寫或不知道的代碼應用一些修正/更改。由於這對我來說很好,我沒有進一步調查這個問題。

此時它可能已經適用於您。接下來的步驟描述瞭如何構建googletest庫並將include目錄添加到項目中。

  • 從github獲取googletest。 https://github.com/google/googletest

  • 運行cmake-gui並配置googletest以便能夠構建。

    發電機:Visual Studio中14 2015年Win64的(我只用了64位,你也可以 試32位)

From the llvm documentation
(no link because not enough reputation: clang.llvm.org/docs/MSVCCompatibility.html):

First, Clang attempts to be ABI-compatible, meaning that Clang-compiled code should be able to link against MSVC-compiled code successfully.

  • 使用默認本地編譯器

哪裏源代碼:(例如C:\libs\googletest\googletest
(因爲頂部目錄中也有googlemock)

構建二進制文件的位置:(例如, C:\libs\googletest\build

  • 取消選中:BUILD_SHARED_LIBS(如果你想建立共享庫) CMAKE_CONFIGURATION_TYPES:調試和發佈(選擇別人,如果你喜歡)
    記住或變化:CMAKE_INSTALL_PREFIX(前C:\libs\googletest\install

Python 2.7被cmake發現,即使我很確定它沒有必要。
按配置並生成。

  • 生成解決方案文件後,轉到上述 指定的目錄(其中建二進制文件,恩。C:\libs\googletest\build)和開解gtest.sln。

  • 選擇調試解決方案配置並右鍵單擊ALL_BUILD和Build。 完成後,右鍵單擊INSTALL和Build。這將創建前面指定的文件夾。

  • CMAKE_INSTALL_PREFIX(前。C:\libs\googletest\install)在那裏 你可能要更改庫的名稱,並添加* d.lib從覆蓋和標誌,這是調試版本的文件保存的。

  • 重複發佈解決方案配置的步驟。 在CMAKE_INSTALL_PREFIX(例如C:\libs\googletest\install)中,您應該找到一個包含目錄和一個lib目錄。

  • 在您的項目屬性 - > VC++目錄下添加包含目錄。 CMAKE_INSTALL_PREFIX<b>\include</b>(前C:\libs\googletest\install<b>\include</b>

  • 在根據屬性項目 - > VC++目錄添加庫目錄。 CMAKE_INSTALL_PREFIX \ lib中

  • 和下Properties - >Linker - >Input - >Additional Dependencies (gtest.lib/gtestd.lib取決於(例C \庫\ googletest \安裝\ lib中。)你的配置)

之後,我能夠建立和運行我的測試。

+0

對不起,遲到的瘋狂迴應。我現在剛剛回到這個問題後,從我的項目中斷了很長時間,我毫不猶豫地將此標記爲公認的答案,因爲我試圖讓gtest與VS2015的內置叮噹聲工具箱一起工作。我確信我可以切換到LLVM快照構建,並讓它編譯正常,如果一切都失敗了,我可以這樣做。 (在這種情況下,我會將這個答案標記爲正確的。) – WhittlesJr

1

由於用較新的LLVM/Clang進行調試時遇到麻煩,我花了一些時間用VS2015,Clang 3.7和googletest。

我編譯googletest庫,如其他答案中所述。然後切換到「與微軟CodeGen(v140_clang_3_7)」鏗鏘3.7「建立我的googletest項目。

誤差的

示例輸出:
.... GTEST /內部/ GTEST-port.h(2384,35):錯誤:使用未聲明的標識符的 '關閉'
直列INT關閉(INT FD){返回關閉(FD); }

在微軟的文檔中,你可以找到:

Example with fdopen
fdopen: This POSIX function is deprecated. Use the ISO C++ conformant _fdopen instead.
https://msdn.microsoft.com/en-us/library/ms235351.aspx

這是相當一些功能相同。

只是谷歌的「視覺工作室xxx」,其中xxx是fdopen或chdir。 你應該得到一個鏈接到你可以找到新方法的文檔。 (通常在名稱前面有一個下劃線。)

一旦你知道要使用什麼,轉到錯誤(使用VS輸出去那裏),在這裏gtest-port.h(2384,35)。

進行更改,此處爲
... return close(fd);
to
... return _ close(fd);
等。

之後,我的測試照常工作。必須擺脫一些警告。

相關問題