5

I just updated to the newest OSX, El Capitan, and I am having problems with compiling a C program. It compiled fine just before the upgrade of the OS. After it I got a warning message already for my LaTeX text editor, Latexian:

Latexian message

But since I don't use preview or compilation inside the program and compile in the terminal with "latex file.tex" it works fine.

Now my problem is with my .c program which includes one of the GSL libraries, here is my header:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>

When compiling I get the following:

performance.c:4:10: fatal error: 'gsl/gsl_rng.h' file not found
#include <gsl/gsl_rng.h>
          ^
1 error generated.

I am guessing something changed in the OSX because of these two situations but the latter is a huge problem for me since I'm finishing my thesis! Hope my question is clear, it's my first.

EDIT:

And I'm guessing this is the problem

El Capitan's System Integrity Protection will shift utilities' functions

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
lailaw
  • 75
  • 1
  • 9
  • How did you install gsl? You may have to use the `-I` option when compiling and specify the directory that is the parent of `gsl/gsl_rng.h` – Michael Petch Nov 05 '15 at 10:38
  • Hi Michael, thanks for answering. I just added an edit that may describe the problem. I am far from knowing about programming, I just know the basics. I downloaded the file from the gsl site to my "Downloads" folder, then i followed instructions, in the terminal I wrote "./configure" and "make" and other commands they instructed! How do I use this -I option? – lailaw Nov 05 '15 at 10:43
  • Did you do a `sudo make install` when finished? – Michael Petch Nov 05 '15 at 10:44
  • @MichaelPetch No, i did not. – lailaw Nov 05 '15 at 10:45
  • The path is the same as always, `/usr/local/include/gsl` I did not even need to install it again. somehow I just need to move it somewhere else because apple messed around (shown in the link after edit) – lailaw Nov 05 '15 at 10:49
  • @MichaelPetch I got the following error message when doing that: `minmax.c:26:10: fatal error: 'gsl/gsl_minmax.h' file not found #include ^ 1 error generated. make[1]: *** [minmax.lo] Error 1 make: *** [install-recursive] Error 1` – lailaw Nov 05 '15 at 10:50
  • @MichaelPetch: `gcc -o performance performance.c -lm -lgsl -std=c99 -O2 -I/usr/local/include ld: library not found for -lgsl clang: error: linker command failed with exit code 1 (use -v to see invocation) ` – lailaw Nov 05 '15 at 10:53
  • With the -L option i get the initial error message `fatal error: 'gsl/gsl_rng.h' file not found` – lailaw Nov 05 '15 at 10:55
  • Have you actually verified that /usr/local/include contains a gsl subdirectory? Like try `ls /usr/local/include/gsl` does it report any files? – Michael Petch Nov 05 '15 at 10:55
  • And when I said add `-L/usr/local/lib` I didn't mean delete `-I/usr/local/include`. They should both appear. As in `-I/usr/local/include -L/usr/local/lib` – Michael Petch Nov 05 '15 at 10:58
  • OMG it's working! I added the -L after the -I as you said and it works now! Compiled with no errors and running! Thank you so much! – lailaw Nov 05 '15 at 11:01
  • Something you might consider is this. GSL should have installed a pkgconfig file. To test this try `echo $(pkg-config --cflags --libs gsl)` from the command line. If that outputs a line of information with -L and -I etc, then in your make file I would remove `-I/usr/local/include -L/usr/local/lib` and replace it with `$(pkg-config --cflags --libs gsl)` . I am glad you got it going though. – Michael Petch Nov 05 '15 at 11:03
  • In which directory should i do this test? I tried that just in the default one when i open a terminal window and i get: `Package gsl was not found in the pkg-config search path. Perhaps you should add the directory containing 'gsl.pc' to the PKG_CONFIG_PATH environment variable No package 'gsl' found` – lailaw Nov 05 '15 at 11:11
  • don't worry about it. On some system gsl.pc might have been installed. I guess not in your environment. – Michael Petch Nov 05 '15 at 11:12
  • Thanks anyway @MichaelPetch! – lailaw Nov 05 '15 at 11:14

3 Answers3

4

When compiling with GCC you may have to manually specify the parent directory that contains the gsl subfolder. Similarly you will have to specify the directory to find the libraries in as well. The include directory can be added as a search path to gcc with the -I option, and the library search path with -L. In your case that is done by adding this to your GCC compilation:

-I/usr/local/include -L/usr/local/lib
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
0

In my case this line solved this linking error

gcc $(gsl-config --cflags) name_of_file.c $(gsl-config --libs) -o name_of_file

See Wiki

MsTais
  • 189
  • 2
  • 9
0

In my case I just needed do install/update gsl

brew install gsl
M.G.
  • 87
  • 7