How to add a default include path for GCC in Linux?
Try setting C_INCLUDE_PATH
(for C header files) or CPLUS_INCLUDE_PATH
(for C++ header files).
As Ciro mentioned, CPATH
will set the path for both C and C++ (and any other language).
More details in GCC's documentation.
How to add default Include and Library path for gcc in Macos for bash?
Following the suggestions of Jonathan Leffler, I got a way around.
I created soft links and it worked.
sudo ln -s ~/Applications/cfitsio/lib/libcfitsio.a /usr/local/lib/libcfitsio.a
sudo ln -s ~/Applications/cfitsio/include/*.h /usr/local/include/
In fact, I copies all the header files from
~/Applications/cfitsio/include
to
/usr/local/include/
and it worked.
I assume soft links also should work.
This might look a very simple solution, but it took hours me to figure out.
How Can I Add An Include Path in GCC C++
Use the -I
command-line argument:
gcc -Ipath
What are the GCC default include directories?
In order to figure out the default paths used by gcc
/g++
, as well as their priorities, you need to examine the output of the following commands:
- For C:
gcc -xc -E -v -
- For C++:
gcc -xc++ -E -v -
The credit goes to Qt Creator team.
Finding out what the GCC include path is
The command
echo | gcc -E -Wp,-v -
will show the include path in use.
Change gcc include path globally
Typically for C++ it should be:
CPLUS_INCLUDE_PATH=/opt/local/include
export CPLUS_INCLUDE_PATH
You can also set that in your .bash_profile for future use.
Update include path in linux
You could create a makefile. A minimal example would be:
INC_PATH=/my/path/to/file
CFLAGS=-I$(INC_PATH)
all:
gcc $(CFLAGS) -o prog src1.c src2.c
From here you could improve this makefile in many ways. The most important, probably, would be to state compilation dependencies (so only modified files are recompiled).
As a reference, here you have a link to the GNU make documentation.
If you do not want to use makefiles, you can always set an environment variable to make it easier to type the compilation command:
export MY_INC_PATH=/my/path/to/file
Then you could compile your program like:
gcc -I${MY_INC_PATH} -o prog src1.c src2.c ...
You may want to define MY_INC_PATH
variable in the file .bashrc
, or probably better, create a file in a handy place containing the variable definition. Then, you could use source
to set that variable in the current shell:
source env.sh
I think, however, that using a makefile is a much preferable approach.
Related Topics
How to Extract Duration Time from Ffmpeg Output
When Should I Wrap Quotes Around a Shell Variable
How to Include All Objects of an Archive in a Shared Object
How to Compare Two Datetime Strings and Return Difference in Hours? (Bash Shell)
Run a Shell Command When a File Is Added
Does Linux Guarantee the Contents of a File Is Flushed to Disc After Close()
Execute Command After Every Command in Bash
Managing Log Files Created by Cron Jobs
Bash Prompt With the Last Exit Code
How to Get File Creation Date/Time in Bash/Debian
Disable Randomization of Memory Addresses
How to Randomize the Lines in a File Using Standard Tools on Red Hat Linux
Core Dump File Is Not Generated
How to Get Gcc to Output Raw Binary
How to Send a HTML Email With the Bash Command "Sendmail"
Print a File, Skipping the First X Lines, in Bash
Using Awk to Count the Number of Occurrences of a Word in a Column