3

This should not be a difficult task. The tried pages are following:

How can I add the include and library path for the cfitsio library for the 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

It 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 time. How can I do so?

I updated my ~/.bash_profile with the 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 the -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 time?

Note:

  • I even tried installing the cfitsio from the /usr/local directory.
  • I installed from /usr/local/cfitsio, but again I had to use -I and -L command with these new locations.

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 the dyld library path to these paths.

echo $LD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH
12
  • Are you using gcc from XCode or some other version? The environment variable on macOS is DYLD_LIBRARY_PATH. Can you install sum links in /usr/local/lib pointing to the installed libraries? Can you do something similar for the headers in /usr/local/include, except it would probably be a link to the directory where you installed cfitsio? Commented Nov 17, 2016 at 15:12
  • You could use make or cmake or pkg-config if you install cfitsio with brew. You need to understand that your project need to be configure to compile. So yes -I and -L and -l are required all time. Don't use environment variable to do that. Commented Nov 17, 2016 at 15:14
  • @Stargateur, I did not use homebrew to install cfitsio, just use make install from their official source package. Commented Nov 17, 2016 at 15:19
  • @BhishanPoudel It's better to use the package manager of your OS. Unless it's doesn't have what you want. I'm not a user of Macos but it's seems that there is a package for cfitsio. Brew will install the lib in PATH that gcc will search by default. So you could avoid -L. Commented Nov 17, 2016 at 15:23
  • @Stargateur It is a great suggestions, but I am looking for another way around. Commented Nov 17, 2016 at 15:30

1 Answer 1

4

Following the suggestions of Jonathan Leffler, I got a workaround.

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 copied all the header files from

~/Applications/cfitsio/include

to

/usr/local/include/

and it worked.

I assume soft links also should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.