I am trying to compile and run my first code in C.
I used this code:
HelloC.h
#include<stdio.h>
// added int to prevent warning
int main()
{
printf("Hello World");
}
I tried compiling with these instructions...
gcc -Wall HelloC.h -o HelloC
chmod +x HelloC
...and this top answer (same thing but replace gcc
with clang
).
The Problem: In both cases ./HelloC
returns exec format error: ./HelloC
.
My Setup
OSX: 10.12.4
clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin