找不到gtest.h文件googletest xcode 7.0

All*_*ala 8 c++ macos xcode unit-testing googletest

我正在尝试按照xcode 7.0中的本指南为我的c ++项目设置谷歌测试框架我到了最后一步Build and Go但是在网上搜索了几个小时后我无法让我的测试项目运行.编译器似乎找不到它需要的头文件.main.cpp:9:10:找不到'gtest/gtest.h'文件.来源是:

#include "gtest/gtest.h"

#include "calc.hpp"

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

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我也试过#include <gtest/gtest.h>同样的结果.

All*_*ala 5

这是我让它工作的方式:

脚步:

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

  2. cd 到下载的源代码文件夹中的文件夹“make”

  3. $ make gtest.a gtest_main.a
  4. 手动将两个静态库文件复制到/usr/local/lib,将头文件目录'include/gtest'复制到/usr/local/include。
  5. 将标题搜索路径 (/usr/local/include) 和库搜索路径 (/usr/local/lib) 添加到您的 xcode 项目设置
  6. 在 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();
    }
    
    Run Code Online (Sandbox Code Playgroud)


小智 5

有时,Xcode无法在框架中找到头文件.您需要其他步骤才能使其正常运行.

  • 构建设置中,完成框架搜索路径以及框架的路径,即gtest.framework.

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

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

完成这些步骤后,gtest应该在Xcode 7.0中运行.