1

I have this bunch of #include statements in the file:

#include "/Users/cooper/Desktop/MyLib/graph_api.h"
#include "/Users/cooper/Desktop/MyLib/mst.h"
#include "/Users/cooper/Desktop/MyLib/dfs.h"
#include "/Users/cooper/Desktop/MyLib/bfs.h"
#include "/Users/cooper/Desktop/MyLib/topo_sort.h"
#include "/Users/cooper/Desktop/MyLib/scc.h"
#include "/Users/cooper/Desktop/MyLib/bipartite.h"
#include "/Users/cooper/Desktop/MyLib/dijkstra.h"
#include "/Users/cooper/Desktop/MyLib/union_find.h"
#include "/Users/cooper/Desktop/MyLib/my_string.h"
#include "/Users/cooper/Desktop/MyLib/2d_array.h"

It might change, though, in the future and I'll have to update a number of lines. Is it possible to have something like

PATH = "/Users/cooper/Desktop/MyLib/
#include PATH + "2d_array.h"

?

alekscooper
  • 795
  • 1
  • 7
  • 19
  • 6
    It is not a part of the makefile per se. It is a command line option. Makefile is just one mechanism to manage compiling – Ed Heal Jul 10 '16 at 10:58
  • 1
    It looks like you're on an OSX system (judging by the paths) which means you are probably using Xcode. In the project settings there must be a place you can enter preprocessor settings, like adding include paths. If you do that, and add `/Users/cooper/Desktop/MyLib` then you can simply do `#include <2d_array.h>`. – Some programmer dude Jul 10 '16 at 10:58
  • 2
    [this answer](http://stackoverflow.com/questions/4743822/generate-include-file-name-in-a-macro) should be useful for you. (I mean wrtie `#define PATH "/Users/cooper/Desktop/MyLib/` and `#include PATH "2d_array.h"`) – mvidelgauz Jul 10 '16 at 10:58
  • I am using XCode, right. – alekscooper Jul 10 '16 at 11:02

1 Answers1

9

Usually your compiler provides an option where you can add pathes where it looks up header files from #include statements.

E.g. for GCC add

-I/Users/cooper/Desktop/MyLib

to your compiler command line.


This option might also be available to be set in your IDE's project settings, or as a variable in your build system.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190