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

I have some C code that includes this header file:
Code:
#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
Code:
#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.
 
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.
 
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.
 
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.
Yep, adding that to my Makefile was the easiest solution
 
Back
Top