-2

My Dlib installation is in multiple places, so I'm writing a script that will search multiple locations for my necessary files to compile:

int main()
{
    try{
        #include <dlib/image_processing/frontal_face_detector.h>
        #include <dlib/image_io.h>
    }catch(...){
        cout << "Location A is incorrect: " << e << endl;
    }


    try{
        #include <dlib/dlib/image_processing/frontal_face_detector.h>
        #include <dlib/dlib/image_io.h>
    }catch(...){
        cout << "Location B is incorrect: " << e << endl;
    }



    return 0;
}

But for some reason, g++ still gives me the same No such file... error:

g++ IWillFindLib--00.cpp -o IWillFindLib--00.o
IWillFindLib--00.cpp:8:59: fatal error: dlib/image_processing/frontal_face_detector.h: No such file or directory
   #include <dlib/image_processing/frontal_face_detector.h>
                                                       ^
compilation terminated.

Now, I know I could just add the locations with g++ -I home/name/dlib, but I want the finished project to run entirely hands-off with no input from the user. How can I make this work?

Rich
  • 1,103
  • 1
  • 15
  • 36
  • 1
    There are a lot of ways you can do something like this, but this is not one of them. You don't really give us a lot of information about the specifics of your problem, so it's hard to advise you on a sensible way to solve it. Maybe include a program (or script) that generates a header file with the necessary `#include`'s in it and have your code `#include` that file. – David Schwartz Jan 09 '17 at 06:40
  • 1
    Possible duplicate of [Can the C preprocessor be used to tell if a file exists?](http://stackoverflow.com/questions/142877/can-the-c-preprocessor-be-used-to-tell-if-a-file-exists) – Martin Bonner supports Monica Jan 09 '17 at 06:43
  • Back from 2008? – Rich Jan 09 '17 at 06:46
  • You need to do this in the build scripts. The old way was autotools but now you'd be using cmake. – Paul Rooney Jan 09 '17 at 06:48

1 Answers1

4

Err. try catch happens at run time. #include happens (very early) at compile time. #include happens before you even really have a C or C++ compiler - it is just a fairly simple text processor at that point.

C++17 has __has_include which does what you want - but you probably don't have a C++17 compiler.

See this answer: https://stackoverflow.com/a/33260104/771073

Community
  • 1
  • 1