libclang not finding headers in <> brackets on Mac with Xcode - c++

Edit:
This program compiles. It's only when run does it fail to find iostream. I'm using the libclang.dylib that is bundled with Xcode.
I've written a small tool to begin working with libclang. I'm trying to parse TranslationUnits. The following program is saved in the file tool.cpp. Once compiled and run, it tries to parse tool.cpp as a TU. It's failing to get a clean run with default headers as it cannot find iostream on my Mac. After several attempts to supply arguments that point to the file, it still doesn't work. Any ideas?
#include "tool.h"
#include <iostream>
int main(int argc, char* argv[]) {
CXIndex index = clang_createIndex(0,0);
const char *args[] = {
"-I/usr/include",
"-I/usr/local/include",
"-I.",
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
//Should be here
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
}
;
Output:
tool.cpp 6:10: 'iostream' file not found

I've got the same issue. I am trying to add CPP to iOS Objective-C. It's not working. I found that this is about next "pain" from Apple because they do not use standard C++ library anymore. I've tried everything that mentioned on this site but haven't found any solution:

Related

Getting Started with ANTLR4 and C++

First time question asker here, so bear with me. So I've got a grammar file from the grammars repository that I'm trying to use with C++. (Developing on macOS). I have no issue generating the lexer and parser using ANTLR. But after that, I have no idea how to run/use the resulting .cpp and .h files. I understand that there is an antlr runtime that I must download, and I have done so from the antlr.org website (gives me two folders, antlr4-runtime and lib), but my novice understanding of C++ seems to be preventing me from getting any further than that. How do I use the runtime to work with these files? I'm not using an IDE, just g++ from the command line. Thank you for any help!
I found this guide helpful: Getting Started with ANTLR in C++. (Ah, saw #ggorlen's comment after.)
If you scroll down on that page to a little past halfway, there's a section titled How to Use ANTLR in C++. I think that's where you are.
I'll copy that example over as SO generally prefers this. Say this is your main.cpp:
#include <iostream>
#include "antlr4-runtime/antlr4-runtime.h"
#include "antlr4-runtime/SceneLexer.h"
#include "antlr4-runtime/SceneParser.h"
#include "ImageVisitor.h"
using namespace std;
using namespace antlr4;
int main(int argc, const char* argv[]) {
std::ifstream stream;
stream.open("input.scene");
ANTLRInputStream input(stream);
SceneLexer lexer(&input);
CommonTokenStream tokens(&lexer);
SceneParser parser(&tokens);
SceneParser::FileContext* tree = parser.file();
ImageVisitor visitor;
Scene scene = visitor.visitFile(tree);
scene.draw();
return 0;
}
You want to include your lexer and parser .h (header) files instead of the SceneLexer/Parser in the example, and also include antlr4-runtime.h. Then run g++ on all your .cpp files, e.g.
$ g++ main.cpp YourLexer.h YourParser.h

CImg Compilation Error: t_normal not in global namespace

I'm currently working on a class assignment that requires the use of the CImg library. To be clear, the assignment is not linking the library into the program; The class is using it access the pixel data for later use in the heart of the assignment.
I'm working in Xcode (OS X 10.10). CImg (2.2.2) is installed from homebrew, and I've managed to navigate the weird way Xcode deals with search paths (added the header to the section), and have successfully-ish included CImg.
my full code is as below.
#include <iostream>
#define cimg_display 0 //I don't need X11 at all
#include "CImg.h"
using namespace cimg_library;
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
However, I get 17 Compile-time errors from CImg.h, which are very unusual, and all of the form:
"No member named 't_normal' in the global namespace; did you mean simply 't_normal'?"
Thinking I might have received a bad download, I have attempted to redownload CImg, with no luck. I have also gotten to this same point with non-homebrew versions of CImg.
To verify the download, I also compiled the examples from the command line and they ran perfectly.
Is there a problem with CImg that I'm not aware of, a problem with Xcode that I'm not aware of, or is there something fundamental that I'm missing (definitely an option, my C-style programming is a little rusty) ?
halp pls.
Your code runs fine if you do this:
Create a new Xcode project, with:
type = "Command Line Tool"
language = "C++"
Then go to "Build Settings" and add the path to the directory containing CImg.h to your "User Header Search Paths"

Unable to understand how header files work?

I am not sure how to properly frame by question but I will try. I have cloned tensorflow repository on my pc and I am trying to run this file.
So I added the following lines to the end of the program
int main(int argc, char const *argv[])
{
tensorflow::StringPiece s20("hello");
std:: cout << s20.data() << std::endl;
return 0;
}
Then I get the error
stringpiece.cc:16:50: fatal error: tensorflow/core/lib/core/stringpiece.h: No such file or directory
#include "tensorflow/core/lib/core/stringpiece.h"
^
compilation terminated.
I can make the code work when I take all the related header files and put them in a separate folder and make a few changes to headers but how can I make this work directly. I also need to understand how
#include "tensorflow/core/lib/core/stringpiece.h"
works.
Basically what I am trying to say is that,I want to run specific subparts of the C++ API without affecting the headers at all. And yes I have installed tensorflow and its working.

Linking Qt in CodeLite

I'm not sure why this is, but 99% of the problems I have with programming in C++ have to do with the gcc linker.
I want to link the Qt library to a project in CodeLite. This is the code I have so far:
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
When I compile, I get the error
/Users/andrew/Dev/C++/COSC 102/elitecod/main.cpp:1:24: error: QApplication: No such file or directory
I have Qt installed (with Homebrew, Mac OS X Lion) in /usr/local/include. Why is this happening, and how can I fix this problem?
The error indicates it can't find the file QApplication. You need to add the Qt 'include' directory to the list of places the compiler should look for it and other header files.
A brief google seems to indicate you may have other problems with Qt, you might want to keep this link handy.

interesting situation in c++

#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char* argv[]) {
std:: cout<<"hello world";
std::cout<<"i am surprise<"<<std::endl;
return (EXIT_SUCCESS);
}
It is very strange because I am using netbeans in Ubuntu 10.04 and run this code. What happens here really makes me surprised; every line of code is marked with red line. For example:
first line indicates that it can't find indicator iostream or can't find file iostream;
second line can't find file stdlib;
third line unable to resolve identifier std and so on,
but it compiles fine and shows me the result "hello world i am surprise"
Please explain why is this happens?
Your IDE's "on the fly" correction tool might not be working correctly (because of bad settings or because fo bugs). I'm guessing it just don't have the access to the default includes.
Your compiler is a separate tool that have access to the includes so it will compile fine anyway.
Try to set the settings correctly or turn the underlining off, or even switch to a better IDE for C++.
The paths for "Code Assistance" are configured separately from your compiler includes. They are usually set when your tool chain is configured but you can check them from the Tools > Options dialog. If your includes are not in any of the paths listed, you will have to add the path. Below is an example of my configuration:
Tools->Options->Code Assistance->C++ Compiler->add path C:\MinGW\bin.
This solved the problem.