Before updating to Mojave I was compiling C programs just fine. I used an older version of gcc, 7.3, that I installed using the instructions found here.
Then I updated to Mojave and tried compiling the simple program that follows with gcc main.c:
#include <stdio.h>
int main(){
printf("Hello World\n");
return 0;}
This results in the following error:
/usr/local/lib/gcc/x86_64-apple-darwin17.5.0/7.3.0/include-fixed/stdio.h:78:10: fatal error: _stdio.h: No such file or directory
#include <_stdio.h>
^~~~~~~~~~
compilation terminated.
If I remove the include it will compile with implicit declaration warnings for printf, but will still compile and run properly, printing Hello World. Does anyone know the issue and how I can fix it?
I figured out how to fix it. I went to
/Library/Developer/CommandLineTools/Packages/
then opened and installed macOS_SDK_headers_for_macOS_10.14.pkg.
Related
Trying to compile a c file that has the header:
#include <sys/wait.h>
I'm using Cygwin to compile it and it keeps giving me this error whenever I type in gcc minishell.c -o minishell:
minishell.c:4:22: fatal error: sys/wait.h: No such file or directory compilation terminated.
Any clue what the heck is going on?
That's because compiler, in this case, does not know how to reach/find sys/wait.h file so that it can include this file in compilation process. To check which all places compiler will try to find the files, refer:
How to tell C++ library path in Cygwin and MinGW
Above post/link also tells about include paths.
I just received a message where someone could not compile a C file.
When they try to compile, it's getting the following error.
$ gcc mpi01.c
mpi01.c:1:17: fatal error: mpi.h: No such file or directory
#include <mpi.h>
^
compilation terminated.
$
I'm sure the C code is present so it must be a problem with the installation, but mpi.h is there.
/opt/mpss/3.6/sysroots/k1om-mpss-linux/usr/src/kernel/drivers/message/fusion/lsi/mpi.h
/usr/include/openmpi-x86_64/mpi.h
/usr/src/kernels/3.10.0-229.20.1.el7.x86_64/include/linux/mpi.h
Does someone know what I could do?
The system is running Centos7.
Edit 1:
To respond to the answers. It is not my code that I am trying to compile. What I did to "ensure" everything is in place for C compiling:
yum install gcc openmpi kernel-devel kernel-headers openmpi-devel
I do not know if I am allowed to post the code, but the following headers are included in the code:
#include <mpi.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
The compiler command line was the following:
vim mpi01.c
module load mpi
gcc -o mpi01 mpi01.c
Resulting in the error above.
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
I installed libsrtp on my ubuntu machine according to the directives in read me, the tests worked fine, and the rptw utility included in libsrtp worked perfectly too. But when I tried to include srtp.h in my HelloWorld! program, it gives me an error that:
fatal error: srtp.h: No such file or directory
compilation terminated.
Concretely, my main file is this
#include "srtp.h"
int main()
{
return 0;
}
My libsrtp.a is present in /usr/local/lib/lib
I used this gcc statement from this blog:
gcc -static main.c -L/usr/local/lib/lib/ -llibsrtp -o main
I will be deeply grateful for any help.
You've found your libsrtp.a , but where is srtp.h ? You'll need to tell the compiler where to search for included files if it's not in a standard location with the -I flag.
Perhaps you need a -I/usr/local/include or -I/usr/local/include/srtp
Note also that -llibsrtp is likely wrong, you need to give the name without the lib prefix. So that makes it -lsrtp
I just started using llvm and trying to print basic commands of llvm, when i tried to execute
clang -cc1 ~/hello.c -ast-print
getting following error
fatal error: 'stdio.h' file not found
#include<stdio.h>
^
int main()
{
printf("hi\n");
return 0;
}
1 error generated.
so please help me out.
Thanks!
With -cc1 you invoke the frontend, not the gcc-compatible compiler driver. The latter knows how to find standard header includes, the former doesn't.
If you want to use -cc1 with files including from standard libraries, then either supply all relevant paths with -I, or just run it on preprocessed files.