This should not be a difficult task, however, I could not solve the issue for hours, so I posted the question here.
The tried links are following:
How to include needed C library using gcc?
How to add a default include path for gcc in linux?
http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Environment-Variables.html#Environment-Variables
how gcc automatically know to include glib library
How to compile gcc with shared library?
http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html
How can I add the include and lib path for cfitsio library for gcc compiler?
Attempt:
I downloaded and installed cfitsio in the path ~/Applications. (NOT /Applications btw).
Then installation commands are:
sudo ./configure
sudo make
sudo make install
Now, let's say I have a program example.c.
Compile: gcc -Wall -O3 example.c -lm -lcfitsio
Does not work.
However,
gcc -Wall -O3 -o example example.c -I /Users/poudel/Applications/cfitsio/include -L /Users/poudel/Applications/cfitsio/lib -lm -lcfitsio
Works
Now I don't want to use flags -I and -L all the times. How can I do so?
I updated my ~/.bash_profile with following lines:
export PATH=$PATH:~/Applications/cfitsio/bin
export LD_LIBRARY_PATH="~/Applications/cfitsio:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="~/Applications/cfitsio/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="~/Applications/cfitsio/lib/pkgconfig:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="~/Applications/cfitsio/zlib:$LD_LIBRARY_PATH"
To check the paths included after running source ~/.bash_profile I used:
echo $LD_LIBRARY_PATH
This shows the added paths correctly.
I have added the paths but this DOES NOT WORK:
gcc -Wall -O3 -o example example.c -lm -lcfitsio
and If i give -I and -L flags with their paths it works.
Can we do something that the above command work without using -I and -L commands all the times?
Note:
I even tried installing the cfitsio from /usr/local directory.
I installed from /usr/local/cfitsio but again I had to use -I and -L command with these new locations.
I am really frustated by this.
The help and suggestion will be greatly appreciated! Thanks.
Update:
I tried to use DYLD instead and added these lines in bash_profile:
export PATH="$(pwd):~/Applications/cfitsio/bin:$PATH"
export PATH="$(pwd):~/Applications/cfitsio/include:$PATH" # fitsio.h is here
export DYLD_LIBRARY_PATH="~/Applications/cfitsio/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="~/Applications/cfitsio/zlib:$DYLD_LIBRARY_PATH"
However, if I run these commands they return empty outputs, I could not set dyld library path to these paths.
echo $LD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH