Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

c++ - g++: Including files that include other files

I am trying to compile a simple script while including a third-party library (https://github.com/google/googletest/tree/master/googletest) on Windows by using cmd and g++ (installed through MinGW). My code looks as follows (unit_test.cpp):

#include <iostream>
#include "folder/importfile.h" //onePlusOne() is declared here, defined in folder/importfile.cpp
#include "gtest/gtest.h" //located at googletest/googletest/include/

int main()
{
    std::cout << "Attempting to compile" << std::endl;
    std::cout << onePlusOne() << std::endl;
    return 0;
}

namespace
{
    TEST(testMath, aTest) //This code might be wrong, but for now I just want it to compile.
    {
        EXPECT_EQ(1000, 10);
    }
} 

I have downloaded the googletest source and thus need to compile it together with my program. If I comment out the googletest parts, the following works fine:

>> g++ -include "folder*.cpp" unit_tests.cpp

However, when trying to compile googletest with it:

>> g++ -include "folder*.cpp" -include "googletestgoogletestsrc*.cc" -I "googletestgoogletestinclude" unit_tests.cpp

I end up with the following error:

./googletestgoogletestsrcgtest-all.cc:41:24: fatal error: src/gtest.cc: No such file or directory
 #include "src/gtest.cc"
                        ^
compilation terminated.

I understand that it cannot find "src/gtest.cc" because there is no src/-folder at the specified search locations ("./" and "googletest/googletest/src/"). What I don't understand is if I need to modify the third-party code so that the includes would state #include "gtest.cc" instead (I'd like to avoid this), or if there is some compilation flag I can set that can help it search at the correct location.

Note: I know that optimally, I would have compiled googletest into a library file or a VS *.sln file like their instructions say, but I a) do not have access to visual studio, b) have had problems with cmake - either my installation is bad, or I'm having problems with "slashes-the-wrong-way". Although CMake/Visual Studio is probably the best solution, it is just not working out for me in this specific case. Additionally, I'd like to understand the commandline solution, as I think it will be valuable general knowledge.

Thanks for any insight!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...