Clang fatal error for -ast-print command - c

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.

Related

Compiling c program with dependencies, h and h0 files

I am trying to compile the gjh solver - written in C - into an executable file in windows. It is available on netlib
I downloaded the c file and am using gcc compiler via WinGW on windows' command prompt. Trying to compile the gjh.c file directly gave me an error that says:
gjh.c:33:21: fatal error: getstub.h: No such file or directory
#include "getstub.h"
compilation terminated.
I assumed that compiling gjh.c requires the dependency getstub.h.
getstub.h is not the only dependency required, there are other dependencies, namely: arith.h, asl.h, funcadd.h, and stdio1.h. All of these files are available on the same link where I found getstub.h. However, arith.h0 and stdio1.h0 are available instead of arith.h and stdio1.h.
Are these files the same? I tried to rename the .h0 files to .h and tried to compile gjh.c, but I got this error:
collect2.exe: error: ld returned 1 exit status
Are the two files the same? If not, is there any way for me to compile the gjh solver successfully into an .exe?
If that's the only problem in compiling, try using the -I switch in gcc:
gcc -I/my/path/to/include/files -o gjh gjh.c
the -I switch hints to gcc where to find your #include files.
I am not sure about the stdio1.h. I think your approach to rename is OK but that reference to external functions such as Sprintf. You need to link with a library defining that. If you know where it comes from, use the -L and -l switch in gcc for that:
gcc -I/my/path/to/include/files -L/my/path/to/library -lnameoflibrary \
-o gjh gjh.c

make file fails with unknown type error?

I am attempting to run a make file for a third party piece of software but I am getting an error when I run it:
$ make
gcc -Iinclude/ -Isrc/ -Wall -Wfatal-errors -Ofast -c ./src/gemm.c -o obj/gemm.o
In file included from ./src/gemm.c:2:
In file included from src/utils.h:5:
In file included from src/list.h:3:
include/darknet.h:491:1: fatal error: unknown type name 'pthread_t'
pthread_t load_data(load_args args);
^
1 error generated.
make: *** [obj/gemm.o] Error 1
I'm not very familiar with C, but from what I can tell pthread_t is a datatype that is similar to an int. I looked at the line that is causing the error:
pthread_t load_data(load_args args);
but don't see anything that would be an obvious cause of the problem.
I looked in my make file and I see this line:
LDFLAGS= -lm -pthread
Could this be part of the problem?
Does anyone know what I might need to do in order to get the pthread_t type recognized so I can run the make file?
I apologize if the answer is obvious - I tried googling the specific error message I was getting but didn't turn much up. Please let me know if I need to post any other other code than what I have already included.
Your error comes from not including the pthread library (assuming you are compiling this for a posix compliant system, if you are on windows pthreads are unlikely to work).
See were the pthread library is installed in your machine and include it in the command line.

Fatal Error Message during Compiling

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.

Error in C program using Fedora

I get the following error when dealing with C using Fedora:
[king#localhost ~]$ gcc -o1 tempdaa.c
tempdaa.c:3:17: fatal error: queue: No such file or directory
#include <queue>
^
compilation terminated.
Any ideas on where the problem is?
gcc is generally what you use to compile C code. If you want to compile C++ code, you'd tend to use g++.
Now it's true that gcc can compile C++ if it's clear you have a C++ program but I think, from memory, that's indicated by the extension rather than the content.
Since your extension is .c rather than something like .cpp or .cc or .cxx, it will definitely think it's C code and behave accordingly.
Hence the C++ header queue will not be available to you.
My suggestion is that you name your C++ source files "correctly", or force the language type explicitly:
gcc -x c++ -o1 tempdaa.c

Linking libsrtp problems

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

Resources