1

Before I start off, please bear with me, I'm very new to cpp with no formal training, and this question may have been asked and answered already, but I'm not sure what to call anything.

So I have a cpp program where I want to use this open source google sling package in. I have the google sling package in the same directory as my main.cpp program, and I can include one header with the path relative to the program, but that header(A) calls other headers(B:) within the package and the relative path to those headers(B:) is not relative to that header(A) file. Here is the error stack:

name@name-ThinkCentre-M83:~/Desktop/c++coding_projects/test_project$ g++ -Isling main.cpp
In file included from main.cpp:7:0:
sling/frame/object.h:25:10: fatal error: sling/base/logging.h: No such file or directory
 #include "sling/base/logging.h"
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
name@name-ThinkCentre-M83:~/Desktop/c++coding_projects/test_project$ ls
bin       obj    test_project.cbp     test_project.layout
main.cpp  sling  test_project.depend  text_testfiles
name@name-ThinkCentre-M83:~/Desktop/c++coding_projects/test_project$ vim main.cpp 
name@name-ThinkCentre-M83:~/Desktop/c++coding_projects/test_project$ cd sling/base
name@name-ThinkCentre-M83:~/Desktop/c++coding_projects/test_project/sling/base$ ls
bitcast.h  flags.cc  libinit.cc  port.h       status.cc    types.h
BUILD      flags.h   logging.cc  registry.cc  status.h
clock.cc   init.cc   logging.h   registry.h   strtoint.cc
clock.h    init.h    macros.h    slice.h      strtoint.h

So sling/base/logging.h is actually there, but since it's being called from sling/frame/object.h, the correct relative path would be ../base/logging.h(at least my limited knowledge tells me so). I think I have to set it up so that it's part of the global path that my cpp compiler searches in for dependencies. Either way I've done something terribly wrong.

I'm looking for a semi quick fix, but also I'd like to avoid this in the future, so a link to the appropriate information would be very much appreciated as well.

Edit: Also tried with same error: g++ -I.sling main.cpp g++ -Itest_project main.cpp g++ -isystem sling main.cpp g++ -iwithprefixbefore "/home/.../test_project/" main.cpp where ... is the path from home to my test project

1 Answers1

0

Thank you melpomene, the correct answer was g++ -I. main.cpp. Case closed.

Thanks to Jerry Jeremiah in the comments for this info:

The #include <x> says "include the file from the include path" and the #include "x" says "include the file from the current directory"

Thus, my program was calling the header file "sling/base/logger.h" from the directory "sling/frame/" (which is where the originally called "sling/frame/object.h" lives) and for obvious reasons couldn't find it there.

  • Do you know why the `-I` was needed? It was needed because the sling header file used `#include ` instead of `#include "x"` to include other files. The `#include ` says "include the file from the include path" (which is defined with -I) and the `#include "x"` says "include the file from the current directory" – Jerry Jeremiah Mar 11 '18 at 23:53
  • I had no idea, but I think you may want to edit that. I see the sling files in the error with `#include "x"`, maybe I'm looking in the wrong place. With your answer, it makes sense that it wouldn't find "sling/base/logging.h" from the directory "sling/frame/", but `-I.` must be specifying where to look for either case of #include. Nonetheless, thanks for the info. – Louis Barto Mar 12 '18 at 00:03