gtest.h file not found googletest xcode 7.0
Asked Answered
P

3

10

I'm trying to setup google testing framework for my c++ project following this guide in xcode 7.0 I got to the last step Build and Go but after hours of searching online I can't get my test project to run. The compiler does not seem to find the headers it needs. main.cpp:9:10: 'gtest/gtest.h' file not found. The source is:

#include "gtest/gtest.h"

#include "calc.hpp"

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

    return 0;
}

I also tried #include <gtest/gtest.h> With same result.

Pediform answered 26/9, 2015 at 12:9 Comment(0)
A
6

Sometimes, Xcode cannot find header files in framework. You need additional steps to make it work.

  • In build settings, complete Framework Search Paths with the path to your framework, which is gtest.framework.

  • Add the framework path and to User Header Search Paths.

  • If Xcode cannot find "gtest/internal/gtest-port-arch.h", you can find it in source folder "googletest/googletest/include". Add it to User Header Search Paths.

After these steps, gtest should work in Xcode 7.0.

Alda answered 27/9, 2015 at 3:53 Comment(1)
It's the framework Headers path that needs to go in User Header Search Paths e.g. ../../googletest/gtest.framework/Headers where ../.. is relative to your xcodeprojShaniceshanie
P
5

Here is how I got it to work:

Steps:

  1. Download the source code $ svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only

  2. cd to the folder 'make' in the downloaded source code folder

  3. run $ make gtest.a gtest_main.a
  4. manually copy the two static library files to /usr/local/lib and copy the header file dir 'include/gtest' to /usr/local/include.
  5. Add Header Search Path (/usr/local/include) and Library Search Path (/usr/local/lib) to your xcode’s project setting
  6. Add linker flag agains gtest. In target setting under "Other Linker Flags". Add /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();
    }
    
Pediform answered 26/9, 2015 at 12:46 Comment(2)
broken link to articleSolana
@mortond Thanks. I removed the broken link to the article. The article does not exist anymore so no use keeping it here.Pediform
A
0

Try deleting the contents of your DerrivedData folder, and re-building.

enter image description here

Amir answered 27/6, 2019 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.