gtest.h file not found googletest xcode 7.0

后端 未结 3 896
Happy的楠姐
Happy的楠姐 2021-02-15 00:45

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\

3条回答
  •  走了就别回头了
    2021-02-15 01:17

    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 
      #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();
      }
      

提交回复
热议问题