2015-09-26 230 views
3

我想为我的C++项目在xcode 7.0中设置guide这个google测试框架我到了最后一步Build and Go,但经过几个小时的在线搜索,我无法让我的测试项目运行。编译器似乎没有找到它需要的头文件。 main.cpp:9:10:找不到'gtest/gtest.h'文件。源是:gtest.h文件未找到googletest xcode 7.0

#include "gtest/gtest.h" 

#include "calc.hpp" 

int main(int argc, const char * argv[]) { 

    return 0; 
} 

我还试图 的#include <GTEST/gtest.h> 随着相同的结果。

回答

2

这是我如何得到它的工作:

步骤:

  1. 下载源代码$ svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only

  2. cd到文件夹 '使' 在下载源代码文件夹

  3. 运行$ make gtest.a gtest_main.a
  4. 手动将两个静态库文件复制到/ usr/local/lib并将头文件dir'include/gtest'复制到/ usr/local/include。
  5. 向xcode的项目设置添加标题搜索路径(/ usr/local/include)和库搜索路径(/ usr/local/lib)
  6. 添加链接标志agains gtest。在“其他链接器标志”下的目标设置中。添加/usr/local/lib/gtest.a

    // main.cpp 
    #include <stdio.h> 
    #include "gtest/gtest.h" 
    #include "calc.hpp" // has function int addition(int,int); 
    TEST(MyFirstTest, TestAddition) { 
         EXPECT_EQ(3, addition(1, 2)); 
    } 
    GTEST_API_ int main(int argc, char **argv) { 
         printf("Running main() from gtest_main.cc\n"); 
         testing::InitGoogleTest(&argc, argv); 
         return RUN_ALL_TESTS(); 
    } 
    
+0

无法链接到文章 – David

+1

@mortond谢谢。我删除了链接到文章的链接。这篇文章不再存在了,所以没有把它留在这里。 –

5

有时候,Xcode中无法找到框架头文件。您需要额外的步骤才能使其工作。

  • 构建设置,完整框架搜索路径与路径的框架,这是gtest.framework。

  • 添加框架路径和用户标题搜索路径

  • 如果Xcode找不到“gtest/internal/gtest-port-arch.h”,您可以在源文件夹“googletest/googletest/include”中找到它。将其添加到用户标题搜索路径

经过这些步骤,gtest应该在Xcode 7.0中工作。

+1

这不适合我:( – nobism