Compiling error with g++ 4.9 on OSX Yosemite - macos

Recently I installed the new version of gcc (4.9) on OSX Yosemite, following the steps that I found on:
https://wiki.helsinki.fi/display/HUGG/Installing+the+GNU+compilers+on+Mac+OS+X
But when I try to compile a simple "Hello World" program, the compiler print the next:
fatal error: iostream: No such file or directory
compilation terminated.
It seems to be a easy problem to solve, but I'm new using this OS. So I don't want to mess it up.
Thank you!.
The code is just a "Hello World" :
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Then I complile with g++ on Terminal like this: g++ hw.cpp -o hw.o
The the result is: fatal error: iostream: No such file or directory

You are probably using gcc instead of g++, try doing the following:
g++ your_source_file.cpp -std=c++11

Related

How to compile code that have qt6 in mingw64?

I try to use mingw-w64 to compile my code that have qt6 library. but, i get long compile error. for testing my environtment is work. I just try to check qt version.
#include <QtCore>
#include <iostream>
int main() {
std::cout << "Qt version: " << qVersion() << std::endl;
}
I installed everything i need with pacman in single line command
pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-qt6
i think library alraedy settle.
now i try to compile the code with this command
g++ version.cpp -o version -I/mingw64/include/qt6/QtCore
-I/mingw64/include/qt6 -I/mingw64/lib/qt6 -lQt6Core -fPIC
i get long failed error compile.

macOS 10.14: Cannot find stdio.h

I am trying to run the following hello world program:
#include <stdio.h>
int main(){
printf("Hello, world!\n");
return 0;
}
With my system's default C compiler located in /usr/bin/gcc, that works as expected. But when I am using the compiler I installed, GCC version 6.4, located in $HOME/usr/bin/, I get the following error:
$ gcc main.cc
main.c:1:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
Any idea on how to fix it? I've tried xcode-select --install/reset. Also, at first, compilation was failing with the system's gcc but I fixed it by creating the /usr/include directory. However, I need to use the compiler I've installed.

How do you compile C++ programs that include LLVM API headers?

I'm trying to use the C++ compiler to compile the following program:
#include <stdio.h>
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/IR/Module.h"
int main( int argc, char* argv[] )
{
if( argc < 2 )
llvm::errs() << "Expected an argument - IR file name\n";
llvm::LLVMContext &context = llvm::getGlobalContext();
llvm::SMDiagnostic err;
llvm::Module* module = llvm::ParseIRFile( argv[1], err, context );
if( !mod )
{
err.print( argv[0], errs() );
return 1;
}
return 0;
}
I'm trying to compile the program using the following command:
clang++ main.cpp -o main
However, when I compile, I'm getting the following compile error:
main.cpp:2:10: fatal error: 'llvm/IR/LLVMContext.h' file not found
#include "llvm/IR/LLVMContext.h"
^
1 error generated.
In this case, I'm not exactly sure how to link the LLVM API headers when compiling main.cpp with Clang.
Any help would be greatly appreciated.
You can use the following command:
g++ -std=c++11 main.cpp `llvm-config --system-libs --cppflags --ldflags --libs core` -o main
Where --libs and --system-libs flags are used for linking and --cppflags takes care of include paths.
Thank You
You need LLVM checked out or installed somewhere on your system. You can download a binary release (with headers and libraries you can build against) as explained here: http://llvm.org/releases/download.html#3.5
You can also check out LLVM from its SVN repository as explained here: http://llvm.org/docs/GettingStarted.html#checkout
Once you do that, I recommend looking at the llvm-clang-samples repository that comes with a Makefiles showing how to build sample programs vs. an up-to-date LLVM.

Why does clang++ lack forward list?

I wrote up a simple C++ program that relies on forward_list like
#include <forward_list>
#include <iostream>
int main() {
std::forward_list<int> my_list;
my_list.push_front(3);
std::cout << my_list.top() << std::endl;
return 0;
}
However, when I compile this program on my Mac with clang++ my_program.cpp -std=c++11 -o my_program, I get this error:
my_program.cpp:1:14: fatal error: 'forward_list' file not found
#include <forward_list>
^
1 error generated.
Why can't clang find forward_list? Other C++11 features are working. For instance, the auto keyword works, albeit a warning appears that tells me that auto is a C++11 feature.
By default clang++ uses an older gcc-4.2 std library which has no C++11 support. You can tell clang to use a C++11-aware std::lib with the command -stdlib=libc++. libc++ has <forward_list>.

xcrun clang --sysroot can not find stdio.h

With Xcode 4.6, under Mac OS X 10.8.2, to compile hello.c, I issued the xcrun command recommended in xcrun gcc cannot find header files but still received the error that the header file stdio.h can not be found.
$ xcrun clang --sysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/ -o hello hello.c
hello.c:2:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
$ cat hello.c
/* C program, Hello World */
#include <stdio.h>
int main()
{
printf("Hello World \n");
}
it should work with :
xcrun clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/
I changed my Build Settings for that project as the Base SDK was not specified. Once I changed it to OS X 10.7 (or whatever you are using should be fine), I was able to compile everything successfully without changing other build configurations.

Resources