【发布时间】:2017-03-18 09:45:38
【问题描述】:
我正在尝试在终端中编译简单的程序,如下所示:
#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 中,然后输入 Terminal cc begin1.txt 如下所示:
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)
我该如何解决这个问题?
【问题讨论】:
-
如果你使用
.cpp而不是.txt,编译器会知道它是什么类型的文件?