macOS 10.14: Cannot find stdio.h - macos

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.

Related

Unable to find Torch header files using nvcc

I'm trying to call some CUDA code from luaJIT (Torch) but I'm running into compiling issues. nvcc seems unable to find my Torch header files. I have CUDA 6.5 and gcc 4.4.7.
nvcc -o im2col -I/deep/u/ibello/torch/include im2col.cu
In file included from /deep/u/ibello/torch/include/THC/THC.h:4,
from utils.h:6,
from im2col.cu:1:
/deep/u/ibello/torch/include/THC/THCGeneral.h:4:23: error: THGeneral.h: No such file or directory
/deep/u/ibello/torch/include/THC/THCGeneral.h:5:25: error: THAllocator.h: No such file or directory
In file included from /deep/u/ibello/torch/include/THC/THC.h:7,
from utils.h:6,
from im2col.cu:1:
/deep/u/ibello/torch/include/THC/THCStorage.h:4:23: error: THStorage.h: No such file or directory
In file included from /deep/u/ibello/torch/include/THC/THC.h:9,
from utils.h:6,
from im2col.cu:1:
im2col.cu includes the following
#include "utils.h"
#include "common.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
where "utils.h" is
#ifndef CUNN_UTILS_H
#define CUNN_UTILS_H
extern "C" { #include <lua.h> }
#include <luaT.h>
#include <THC/THC.h>
THCState* getCutorchState(lua_State* L);
#endif
This is relatively weird since the mentioned files are indeed in the include location I gave to the compiler..
ls /deep/u/ibello/torch/include/THC
THCAllocator.h THCDeviceTensor.cuh THCDeviceTensorUtils-inl.cuh THC.h THCReduce.cuh THCTensorConv.h THCTensorMath.h
THCApply.cuh THCDeviceTensor-inl.cuh THCDeviceUtils.cuh THCReduceAll.cuh THCStorageCopy.h THCTensorCopy.h THCTensorRandom.h
THCBlas.h THCDeviceTensorUtils.cuh THCGeneral.h THCReduceApplyUtils.cuh THCStorage.h THCTensor.h THCTensorSort.h
Any ideas about what I'm doing wrong?
Thx in advance!
It seems that this compile command:
nvcc -o im2col -I/deep/u/ibello/torch/include im2col.cu
did not give the necessary search paths for the compiler to find the header files like THGeneral.h that were located in /deep/u/ibello/torch/include/TH
The solution was to specify a compile command like this:
nvcc -o im2col -I/deep/u/ibello/torch/include -I/deep/u/ibello/torch/include/TH im2col.cu

Compiling error with g++ 4.9 on OSX Yosemite

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

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.

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.

mingw32 linker error when including QDebug

I have this minimal example:
QT -= gui
CONFIG += qt console
SOURCES += main.cpp
#include <QDebug>
int main(int argc, char** argv)
{
return 0;
}
which gives this link error when building the project:
c:/qtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid argument
The link command looks like this:
g++ -Wl -Wl -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o -L"c:\QtSDK\Desktop\Qt\4.8.1\mingw\lib" -lQtCored4
My setup:
Windows XP SP3
Qt SDK version 1.2.1 (QtCreator 2.4.1, Qt Desktop version 4.8.1) (fresh install at C:\QtSDK\)
MinGW32 version 4.4.0 (included in Qt SDK at C:\QtSDK\mingw\)
If I remove the #include <QDebug>, it compiles fine. If I include some other Qt header file, like for example QCoreApplication, it compiles fine, too.
EDIT: Here is a very strange minimal example. Consider an empty main function like above. Now if i put these includes, it fails to link:
#include <QWidget>
#include <QVariant>
But if I remove one of them, it links without an error.
What's the problem? Why doesn't mingw tell me what the invalid argument is?
Im wondering is the linker could not find the lQtCored4 lib? Is it actually in the -L directory?

Resources