# How to add "/usr/local/include" to my $PATH?



## Aaron_VanAlstine (Nov 16, 2022)

I have some C code that includes this header file:

```
#include <json-c/json.h>
```

I'm getting *fatal error: 'json-c/json.h' file not found *because my path variable doesn't include /usr/local/include/json-c where the json.h header exists. Of course it compiles using a 
	
	



```
#include </usr/local/include/json-c/json.h>
```
 header but that's unacceptable.

How can I add to $PATH without throwing a *Bad : modifier in $ '/'* error? My user shell is bash and the PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/aaronvan/bin. I'm seeing a lot of solutions on the internet (i.e. add to login.conf) but no joy.


----------



## Styrsven (Nov 16, 2022)

Your $PATH is used by the shell to find executables. You want to tell the compiler where to look for include files, normally by adding -I/thepathyouwant as a parameter to the compiler.
How to do that depends.
If you use a build system (automake, Cmake,  or something else) you should check how to do it in the corresponding documentation/help.
If you use a handwritten makefile or just start the compiler it should be easy.


----------



## Paul Floyd (Nov 16, 2022)

You need to tell us more about how you are building your software.

First thing, when including files the convention is to use angle brackets for system headers (like '#include <algorithm>') and to use double quotes for user headers (like '#include "widget.h"'). The difference is that the compiler will search the system include directories for <> includes and not for "" includes. (There are some contrarians like John Lakos that recommend always using <> includes). The question then is what are the system include dirs?

See this SO thread for how you can get the system include directories with clang.

As Styrsven said, if the header is not in a system include directory or the current directory then you need to specify "-I" to the compiler.

If you are using "make" then the usual way to do this is with the CPPFLAGS make variable (that's C pre-processor, not C++ which is CXXFLAGS). So in your Makefile you need something like

CPPFLAGS += -I/usr/local/include

(assuming that the standard variables are being used which is sadly not always the case). If you're using a different make system, there will be some simular variable.


----------



## Aaron_VanAlstine (Nov 16, 2022)

Paul Floyd said:


> You need to tell us more about how you are building your software.
> 
> First thing, when including files the convention is to use angle brackets for system headers (like '#include <algorithm>') and to use double quotes for user headers (like '#include "widget.h"'). The difference is that the compiler will search the system include directories for <> includes and not for "" includes. (There are some contrarians like John Lakos that recommend always using <> includes). The question then is what are the system include dirs?
> 
> ...


Yep, adding that to my Makefile was the easiest solution


----------



## mer (Nov 16, 2022)

Aaron_VanAlstine said:


> Yep, adding that to my Makefile was the easiest solution


It was also the correct solution.  That's why compilers have flags and variables you use to configure things like include paths.


----------



## Phishfry (Nov 16, 2022)

Paul Floyd said:


> the CPPFLAGS make variable (that's C pre-processor, not C++ which is CXXFLAGS).


Thank You for that factoid.
I see that in my NanoBSD 'WITHOUTS_' and now I know what it is.


----------

