問題描述
網(wǎng)站上沒有記錄,人們似乎在設(shè)置框架時(shí)遇到問題.有人可以展示示例項(xiàng)目設(shè)置的分步介紹嗎?
It is not documented on the web site and people seem to be having problems setting up the framework. Can someone please show a step-by-step introduction for a sample project setup?
推薦答案
Arlaharen 所說的基本上是對(duì)的,只是他省略了解釋鏈接器錯(cuò)誤的部分.首先,您需要構(gòu)建您的應(yīng)用程序沒有 CRT 作為運(yùn)行時(shí)庫(kù).無(wú)論如何,您應(yīng)該始終這樣做,因?yàn)樗_實(shí)簡(jiǎn)化了應(yīng)用程序的分發(fā).如果您不這樣做,那么您的所有用戶都需要安裝 Visual C++ 運(yùn)行時(shí)庫(kù),而那些不安裝的用戶會(huì)抱怨他們的系統(tǒng)上缺少神秘的 DLL……因?yàn)殒溄有枰~外花費(fèi)幾百 KB靜態(tài)地使用 CRT,您以后在支持方面會(huì)省去很多麻煩(相信我 - 我已經(jīng)通過艱難的方式學(xué)會(huì)了它!).
What Arlaharen said was basically right, except he left out the part which explains your linker errors. First of all, you need to build your application without the CRT as a runtime library. You should always do this anyways, as it really simplifies distribution of your application. If you don't do this, then all of your users need the Visual C++ Runtime Library installed, and those who do not will complain about mysterious DLL's missing on their system... for the extra few hundred kilobytes that it costs to link in the CRT statically, you save yourself a lot of headache later in support (trust me on this one -- I've learned it the hard way!).
無(wú)論如何,要做到這一點(diǎn),你去目標(biāo)的屬性 -> C/C++ -> 代碼生成 -> 運(yùn)行時(shí)庫(kù),它需要為你的發(fā)布版本設(shè)置為多線程"和多線程"Debug"用于您的調(diào)試版本.
Anyways, to do this, you go to the target's properties -> C/C++ -> Code Generation -> Runtime Library, and it needs to be set as "Multi-Threaded" for your Release build and "Multi-Threaded Debug" for your Debug build.
由于 gtest 庫(kù)是以相同的方式構(gòu)建的,因此您需要確保鏈接的是 it 的正確版本,否則鏈接器將拉入運(yùn)行時(shí)庫(kù)的另一個(gè)副本,這是您看到的錯(cuò)誤(順便說一句,如果您使用 MFC,這應(yīng)該沒有區(qū)別).您需要將 gtest 構(gòu)建為調(diào)試和發(fā)布模式并保留兩個(gè)副本.然后,您在發(fā)布版本中鏈接 gtest.lib/gtest_main.lib,在調(diào)試版本中鏈接 gtestd.lib/gtest_maind.lib.
Since the gtest library is built in the same way, you need to make sure you are linking against the correct version of it, or else the linker will pull in another copy of the runtime library, which is the error you saw (btw, this shouldn't make a difference if you are using MFC or not). You need to build gtest as both a Debug and Release mode and keep both copies. You then link against gtest.lib/gtest_main.lib in your Release build and gtestd.lib/gtest_maind.lib in your Debug build.
此外,您需要確保您的應(yīng)用程序指向存儲(chǔ) gtest 頭文件的目錄(在屬性 -> C/C++ -> 常規(guī) -> 附加包含目錄中),但如果遇到鏈接器錯(cuò)誤,我假設(shè)您已經(jīng)設(shè)法使這部分正確,否則您將首先處理更多的編譯器錯(cuò)誤.
Also, you need to make sure that your application points to the directory where the gtest header files are stored (in properties -> C/C++ -> General -> Additional Include Directories), but if you got to the linker error, I assume that you already managed to get this part correct, or else you'd have a lot more compiler errors to deal with first.
這篇關(guān)于如何使用 Visual Studio 2005 設(shè)置 Google C++ 測(cè)試框架 (gtest)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!