2017-05-14 5 views
-1

は私がthis codeを使用:CのHelloWorldのexecフォーマットエラー

HelloC.h

#include<stdio.h> 

// added int to prevent warning 
int main() 
{ 
    printf("Hello World"); 

} 

私はthese instructionsでコンパイルしてみました...

gcc -Wall HelloC.h -o HelloC 
chmod +x HelloC 

...とthis top answer(同じものですが、gccclangに置き換えてください)。

問題:どちらの場合も、./HelloCexec format error: ./HelloCを返します。

マイセットアップ

OSX:10.12.4

打ち鳴らす--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 
+2

あなたのコードはなぜ '.h'ファイルになっていますか? –

+0

'chmod'の使い方はどうでしたか?それはあなたがリンクしている指示の一部ではありません。 –

+0

1)コードは '.h'ではなく' .c'ファイル内に存在する必要があります。 2)引数を取らない関数は、任意の量の引数で呼び出されるのを避けるために、 'func_name(void)'のように見えるはずです。 3)実際には 'main'から何かを返すべきです。 4)あなたのコンパイラは、出力ファイルを自動的に実行可能にする必要があります。もしあなたが 'chmod'を使う必要があれば、それは悪い印です。 – Siguza

答えて

1

クレジット@ScottHunterへと@Siguz a

ファイル拡張子として.c not .hを使用する必要がありました。

関連する問題