Working with CLang in c++ - c++

I have a compilation error in my program related to the included files, in my program I am including this files:
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
The error message I get when I compile the program using g++ is:
In file included from /usr/include/clang/AST/APValue.h:17:0,
from /usr/include/clang/AST/Decl.h:17,
from /usr/include/clang/AST/RecursiveASTVisitor.h:17,
from FindClassDecls.cpp:2:
/usr/include/clang/Basic/LLVM.h:20:34: fatal error: llvm/Support/Casting.h: No such file or directory
compilation terminated.
I don't have any idea how to solve the problem, and also I am not sure that I installed the CLang library correctly, so can you please tell me how to solve the problem or how to install it correctly on linux (Ubuntu).

It seems that you have the Clang headers installed, but not the LLVM headers (which Clang relies upon). When you are compiling your code, you need to pass the path of LLVM headers with -I to your compiler, as usual.
I'd grab a pre-built Clang+LLVM from the Download page and compile/link against that.

sudo apt-get install libclang-3.8-dev # or libclang-3.9-dev

Related

Xcode 11.1: iostream' file not found

I just updated my MacBook Pro to macOS Catalina 10.15, and tried to compile and run a C++ command line program, but I had a problem which didn’t exist on previous versions;
This is simply the code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
return 0;
}
The code compiles and outputs the expected, but still the Xcode says:
fatal error: 'iostream' file not found
I tried changing the Build Settings/C++ Standard Library to libstdc++, but a warning says:
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead
And the same iostream error still exists.
I'm compiling from the command line, and none of the answers listed here (or elsewhere) worked for me.
What does seem to work (so far) is to add the following to .profile or whatever script your terminal uses to start up: (zsh, csh, bash, etc.)
export C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
You will probably have to change MacOSX10.15.sdk whenever you upgrade your operating system.
C_INCLUDE_PATH and CPLUS_INCLUDE_PATH are options for the clang toolchain rather than MacOS environment, so hopefully this solution will work long-term, unlike xcode-select --install (which won't fix the include directories on an upgrade) or ln -s ... /usr/include (which is now forbidden by System Integrity Protection).
I had the same problem and used the following youtube video to fix it.
https://www.youtube.com/watch?v=hrPm7tWC-BI&feature=youtu.be
or you can follow this path. Make sure to include the quotation marks
Project - Build Settings - Search Paths - Headers Search Paths, and add the following path:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/"
So, I restarted my laptop and everything seems to be fine right now, thanks for those who tried to help.
libstdc++ is not OK for Xcode Build & Compile time,
libstdc++ is OK for iPhone Run Time
From answer recommended by #Alan Birtles
libstdc++ Support was removed from the iOS 12.0 Simulator runtime, but
it remains in the iOS 12.0 (device) runtime for binary compatibility
with shipping apps.
I encountered this when declaration in .hpp file.
#include <iostream>
#include <string>
OK with
#ifdef __cplusplus
#include <iostream>
#include <string>
// usage code
#endif
I tried a fresh Catalina install with Xcode. I copied and pasted your code into "test.cpp" and then ran:
clang++ test.cpp
in the same directory as the "test.cpp" file from Terminal. The result was an "a.out" file which when run:
./a.out
output the required "Hello, World!" result. Hopefully that is of some use (as a point of reference).

<glad/glad.h>: No such file or directory

I'm following this tutorial to learn OpenGL, but I'm having trouble compiling since the compiler can't find one of the header files.
This is the file I'm trying to compile:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
return 0;
}
To compile, I'm using
$ gcc -o sandbox sandbox.cpp -lGL -lGLU -lglut
and I get the following error:
sandbox.cpp:1:23: fatal error: glad/glad.h: No such file or directory
#include <glad/glad.h>
^
compilation terminated.
I followed the first two sections of this wiki
to install OpenGL and libraries.
I think the problem is either the wrong compile command or a flaw in my OpenGL installation.
GLAD is a function loader for OpenGL. This tutorial explains how to set it up.
The tutorial explains the purpose of GLAD:
Since there are many different versions of OpenGL drivers, the location of most of its functions is not known at compile-time and needs to be queried at run-time.
Setup of GLAD involves using a web server to generate source and header files specific to your GL version, extensions, and language. The source and header files are then placed in your project's src and include directories.
If you are looking at this simple GLFW example you can remove the glad/gl.h include, and the
gladLoadGL(glfwGetProcAddress);
line further down.
If you are on linux, ubuntu for example,
you don't need glad, just add these 2 headers instead:
#include <GLES2/gl2.h>
#include <EGL/egl.h>
If the example is saved as glfw_ex2.c you can compile it at the command line like this:
g++ glfw_ex2.c -lglfw -lGLESv2
Of course, linmath.h must be present in the same directory for this example.
If anything is missing, you can install it like this and try compiling again:
sudo apt install libglfw3-dev libgles2-mesa-dev libegl1-mesa-dev
sudo apt install build-essential
then run it like this:
./a.out

How to install clang header files?

I have clang installed on my MacOS (in /usr/bin/clang ) which I think comes installed by default on Mac, however, when I try to include clang header files in a script, it says they are not found
Example.cpp:1:10: fatal error: 'clang/Driver/Options.h' file not found
Question: is it necessary (and possible, if so, how) to install the header files when clang is already installed and built on the MacOS system (or does clang itself need to be reinstalled at the same time as all the desired development tooling packages and their header files are installed)?
#include "clang/Driver/Options.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/Rewrite/Core/Rewriter.h"
When you use double quotes for including the libraries it will search the current directory which your c/cpp file or application resides in. Try with < and > or compile with the -I option
The question asked if it was necessary and possible to install the header files on MacOS which comes with clang installed already. The desired header files weren't installed and in order to install them it is possible to clone the repo and build llvm and clang (as described in the llvm getting started guide http://llvm.org/docs/GettingStarted.html) , so that it's in effect installed twice on the system.

MinGW stdio.h : No such file or directory

i know that there are some other posts with this problem but the solutions that where given weren't helpful for me.
I just installed MinGW on my Windows 7 laptop.
So i wrote a hello world program to try the compiler but when i compile it i get this message: hello.c:1:20: fatal error: stdio.h: No such file or directory
#include
compilation terminated.
I don't know what to do,i have installed mingw on c directory and changed the path to mingw's bin. i use the command gcc hello.c -o hello to compile and the code is this:
#include <stdio.h>
main()
{
printf ("Hello,world\n");
}
Any suggestions ?
Thank you.

Missing header files on Mac 10.6.8 stop compilation (SNAP software installation)

I'm trying to install Stanford Network Analysis Project.
I work on MacOS 10.6.8. Yesterday I've downloaded the latest compatible version of Xcode (3.1.4) in order to get the GCC package with a C++ compiler.
When I run the "make" command in my Unix Terminal I get hundreds line of errors.
The first one is about a missing file named "poll.h".
make -C snap-core
g++ -c -std=c++98 -Wall -O3 -I/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys -I/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers Snap.cpp -I../glib-core
In file included from Snap.h:8,
from Snap.cpp:4:
../glib-core/base.h:68:24: error: sys/poll.h: No such file or directory
../glib-core/base.h:75:21: error: netdb.h: No such file or directory
../glib-core/base.h:76:25: error: arpa/inet.h: No such file or directory
I've searched on my hard drive where this "poll.h" file was. I can't find it. I can't find netdb.h or inet.h and a few others either.
These files are not the first ones to be included. I'm saying this to make clear that some files are found but some others are missing. This is what actually happen before I encouter the error:
#include <stdint.h>
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <unistd.h>
#include <signal.h>
#include <sys/poll.h>
As several files are missing I believe I'm missing something big in this issue. Nonethelless I've found out a way to download "poll.h" here. I don't feel comfortable using it... How can I be sure it's the proper file ? What about the other missing files ?
Any suggestion would be really appreciated.
Thanks a lot. Nicolas.