2017-03-18 11 views
-3

マックターミナルに簡単なコードをコンパイル:それは言うbegin1.txtそれ保存私はこのように、ターミナルで簡単なプログラムをコンパイルしようとしています

#include <stdio.h> 
int main() 
{ 
int a; 
printf("Enter length of square:"); 
scanf("%d",&a); 
printf("Perimeter of your square is:%d\n", 4*a); 
return 0; 
} 

をファイルbegin1.txtにホームディレクトリで、その後、ターミナルのccを入力like:

ld: warning: ignoring file begin1.txt, file was built for unsupported file format (0x23 0x69 0x6E 0x63 0x6C 0x75 0x64 0x65 0x20 0x3C 0x73 0x74 0x64 0x69 0x6F 0x2E) which is not the architecture being linked (x86_64): begin1.txt 
Undefined symbols for architecture x86_64: 
    "_main", referenced from: 
    implicit entry/start for main executable 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

どうすればこの問題を解決できますか?

+2

を.cpp'使用している場合は、' .txt'コンパイラはそれがあるファイルの種類を知っているのだろうか? –

答えて

0

LD:警告: begin1.txt無視ファイル、ファイルがサポートされていないファイル形式用に構築した(0x23 0x69の0x6Eは0x63 0x6C 0x75 0x64 0x65 0x20の0x3cの0x73 0x74 0x64 0x69の0x6F 0x2E)これがリンクされアーキテクチャない(x86_64版):

begin1.txt

コンパイラによって発行されたエラーステートメントは、ファイルが.txtというファイル拡張子で保存されていることを示しています。これにより、C++ファイルではなくテキストファイルになります。あなたは.cppファイルの拡張子で終わるためにあなたのファイル名を変更する必要があります:あなたは `の代わりに

begin1.cpp 
関連する問題