"gsl/gsl_rng.h' file not found" after OSX El Capitan upgrade - c

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

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

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

In my case I just needed do install/update gsl
brew install gsl

Related

fatal error: stdio.h: No such file or directory

I have a problem with #include <stdio.h> on mac Mojave 10.14.1
I have a default gcc compiler together with other gcc compilers.
DorothyeMacBook:Desktop dorothy$ which gcc
/usr/local/bin/gcc
The version is
DorothyeMacBook:Desktop dorothy$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin15.6.0/7.1.0/lto-wrapper
Target: x86_64-apple-darwin15.6.0
Configured with: ../gcc-7.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 7.1.0 (GCC)
Now I am in the path :
/Users/dorothy/Desktop
I have stdio.h in the lib
DorothyeMacBook:Desktop dorothy$ find /usr -name "stdio.h"
find: /usr/sbin/authserver: Permission denied
/usr/local/include/c++/7.1.0/tr1/stdio.h
/usr/local/include/c++/4.9.2/tr1/stdio.h
/usr/local/lib/gcc/x86_64-apple-darwin15.6.0/7.1.0/include/ssp/stdio.h
/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin18.2.0/8.2.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin18.2.0/8.2.0/include-fixed/stdio.h
However when I compile the file under the current path /Users/dorothy/Desktop Terminal will give me an error:
DorothyeMacBook:Desktop dorothy$ gcc inverse.c -o inv
inverse.c:1:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^~~~~~~~~
compilation terminated.
I still have a problem linking gcc with stdio.h on my mac. However, I have found an alternative way to compile the program with gcc. I typed brew install gcc in my terminal, that means a new gcc8.0.2 will be installed.(which is my case, I don't know what gcc you will get) Then I use gcc-8 instead of gcc to compile my program. In this way, the new gcc8.0.2 is invoked.
You can check the command name for gcc variants by going to /usr/local/bin All the names for gcc commands are listed there. As for me, those are
g++
g++-8
gcc
gcc-8
If you have further question, you can contact me and I will give more details.
#Jonathan Leffler is right. Apple made another big cake for us.
Since /usr/include has been moved (now it in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include after you install commandline tools), old versions of gcc build cannot find the most bottom level include files. And this is a problem. (What are there in their head) So only you are developer you use /usr/include?
This is NOT Unix-like.
Here is what happened. For gcc-4.9(gcc-4.9 and gcc-9 below are all brew gcc.), the include search paths are:
enter ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/usr/local/Cellar/gcc#4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include
/usr/local/Cellar/gcc#4.9/4.9.4_1/include
/usr/local/Cellar/gcc#4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include-fixed
/System/Library/Frameworks
/Library/Frameworks
End of search list. here
There is system level file stdio.h, this is why stdio.h cannot be found.
The problem in:
inverse.c:1:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^~~~~~~~~
compilation terminated.
is:
Refer to /usr/local/Cellar/gcc#4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include/ssp/stdio.h
#ifndef _SSP_STDIO_H
#define _SSP_STDIO_H 1
#include <ssp.h>
#include_next <stdio.h>
#include_next means include next one name stdio.h, this one is just a guider.
Give a deprecated shot. cp all files in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include to /usr/local/Cellar/gcc#4.9/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include-fixed, gcc-4.9 will work again.
But for gcc-9 the path problem is fine. See:
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include # key path
/usr/local/Cellar/gcc/9.1.0/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0/include
/usr/local/Cellar/gcc/9.1.0/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
End of search list.
Actually this bug can be simply fixed by reinstall xcode commandline tools, after that gcc-4.9 will work again.

C Compile Fatal Error 'file not found' from ImageMagick Install Mac OS

I am trying to compile a C program that requires Image Magick's MagickWand.h:
#include "wand/MagickWand.h"
But my Image Magick was installed through Homebrew on my Mac so I changed the include to the actual location:
#include </usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6/wand/MagickWand.h>
However, when I compiled the program I received the following error:
/usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6/wand/MagickWand.h:71:10: fatal error: 'wand/method-attribute.h' file not found
#include "wand/method-attribute.h"
Now I've been going into the .h files when this error crops up and changing their #includes so that they are pointed correctly (because that appears to be the problem), but there is always a new error here and I'd rather not spend hours manually updating these because of a Homebrew install. Does anyone have any suggestions on how to fix this without manually updating each file? I'm not sure exactly what the problem is so perhaps there is a more elegant solution.
Your code should include the MagickWand library as system headers, and keep the generic path. This will keep your future compiling from breaking when the system/library updates.
#include <wand/MagickWand.h>
Tell your C compiler where homebrew installed ImageMagick by setting the preprocessor include flag -I, and linking/library options with the -L & -l flags.
example:
clang -I/usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6 \
myProject.c -o myProject.o \
-L/usr/local/Cellar/imagemagick/6.8.9-7/lib \
-lMagickWand-6.Q16 \
-lMagickCore-6.Q1
To simplify the whole process, ImageMagick ships MagickWand-config utility. This will take care of libs, includes, and definitions for you.
example:
CFLAGS=$(MagickWand-config --cflags)
LFLAGS=$(MagickWand-config --libs)
clang $CFLAGS myProject.c -o myProject.o $LFLAGS

Compile error when using FFMPEG library

I have tried to compile a C program using FFMPEG but every time I compile it fails at the include statement:
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
Gcc provides this error message:
libavcodec/avcodec.h: No such file or directory
I have installed FFMPEG and created the shared libraries, but when I try to link those libraries when I compile I get the same error.
gcc main.c -L ffmpeg_build/lib -l ffmpeg_build/include/libavcodec/avcodec.h
Do I get this error because I am linking the library incorrectly, or is there some other issue?
This is the first time I am using someone else's library, so please excuse me if I am asking a silly question.
A lowercase -l is a linker option used to specify libraries. They might look like libsomething.a and becomes -lsomething in the linker invocation. In order to add a directory to the header search path, use a capital i, -I.
gcc main.c -L/some/path/ffmpeg_build/lib -I/some/path/ffmpeg_build/include

Still get 'curl/curl.h: No such file or directory' in spite of all looks proper

I installed on windows curl 7.28.0 from curl-7.28.1-devel-mingw32.zip through minGW console to default directory like:
./config && make && make install
All needed headers (aka curl.h, types.h ...) I see in C:\MinGW\msys\1.0\local\include\curl
libcurl.pc placed in C:\MinGW\msys\1.0\local\lib\pkgconfig\
libcurl.a, libcurl.dll.a and libcurl.la placed in C:\MinGW\msys\1.0\local\lib.
My download_file.c file includes are:
...
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
...
I try to compile the C code with followed command through gcc:
$ gcc -IC:/MinGW/msys/1.0/include/
-IC:/MinGW/msys/1.0/local/include/curl
-IC:/MinGW/msys/1.0/local/lib/pkgconfig
-o download_file download_file.c -llibcurl -lcurl
with absolute path get the same error:
gcc -I/include/
-I/local/include/curl
-I/local/lib/pkgconfig
-o download_file download_file.c -llibcurl -lcurl
But I still get an error:
download_file.c:21:23: fatal error: curl/curl.h: No such file or directory compilation terminated.
row 21 is #include <curl/curl.h>
What I did wrong? Please help.
You have the curl/ directory in the source code, but also in the option.
It seems the option should point out the higher-level directory in which curl/ is, so it should be something like:
-I/local/include/
I think the problem is likely that you give your include paths on the command line in the Win32 path format. This is not the same as the one used by msys (or ultimately Cygwin).
Try these:
$ gcc -I/include/
-I/local/include/curl
-I/local/lib/pkgconfig
...
Hope I got the absolut paths right, but you can check in your msys shell.
What ticked me off was that you use ./config, which wouldn't work from the Command Prompt, but works from the msys shell. So you need to give paths that all the programs in MinGW understand.
Basically, most programs in MinGW only have the concept of a single file system root, like on any unixoid system, while Win32 has multiple (the drive letters). Since the MinGW programs are linked accordingly, you need to give paths that they understand.
Thank you very much to #0xC0000022L and #unwind. By your help I fixed my problem.
0xC0000022L you are right about absolute path
unwind you are right about -I/local/include/ instead -I/local/include/curl
I found other problem: -L/local/lib instead -I/local/lib.
So this is a working command:
gcc -I/include/
-I/local/include
-L/local/lib
-o download_file download_file.c -llibcurl -lcurl

gcc compiler error: "cannot find -lcs50 collect2: Id returned 1 exit status"

I have a problem in 'c' language inside compiling with gcc.
I am using "Cygwin" with (gcc-core, gcc-g++, gdb, make & other supportive packages) inside windows xp.
I installed "Cygwin" on this path "C:\Cygwin\".
My home directory: "C:\Cygwin\home\Bhanu Pratap"
I copied "cs50.h" and "cs50.c" inside my working directory which is also under "C:\Cygwin\home\Bhanu Pratap".
This is code inside my hello.c file
#include "cs50.h"
#include <stdio.h>
int
main(void){
string name = "David";
printf("O hai, %s!\n", name);
}
This is command under bash (Cygwin)
gcc -o hello hello.c -lc50
I get this error:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/id: cannot find -lcs50
collect2: Id returned 1 exit status
Please help me where i am wrong?
I'm also using the cs50 library file, and I've noticed in the code that you've used is :
#include "cs50.h"
#include <stdio.h>
and also this command :
gcc -o hello hello.c -lc50
just wondered why you used quotation marks, instead of '< >'
and the last part of the command -lc50
we normally use it this way:
#include <cs50.h>
#include <stdio.h>
and -lcs50
hope this helps \m/
To be able to use -lcs50, you'll first need to build that library (cs50) from its source code (cs50.c).
Alternatively, you could simply:
gcc -o hello hello.c cs50.c
assuming cs50.c doesn't have other dependencies.
I am using DJGPP (gcc) compiler in Windows XP for CS50 edX course.
I have tried different solutions from answers, but none of them helped me (though Mat gave me a clue).
Here is a solution:
1) copy cs50.h and cs50.c from library50-c-5.zip into a directory, where your .c source file, which you want to compile, is located.
2) type into your .c source file: #include "cs50.h"
3) compile your .c source file (at cmd.exe prompt, for example): gcc custom.c -o custom cs50.c
You may copy cmd.exe from "`C:\WINDOWS\system32" folder into your working folder (with your .c files). In this case you don't have to change directory for navigating to your working files, when you start up command prompt window.
See the link http://manual.cs50.net for relevant guidance about guidance about installing the cs50.h library. They have a precompiled version of the cs50 library that can be downloaded and installed. It is worth a try. They used gcc to compile the library, and they beginning to switch over to clang, which can also produce 64 bit compatible libraries, which is going to more useful in the future.

Resources