当我尝试在Mac中编译此非常简单的C 程序时,我会遇到错误(Highsierra:版本10.13.3(。此Mac中使用的GCC版本为5.3.0。
这是C 程序:
#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
int main()
{
cout<<sin(1);
}
从较早的问题中回答后,我使用xcode-select --install
在上述命令行安装后,当我尝试使用
编译此程序时gcc filename.cpp -o filename.out
我有以下错误:
/var/folders/mp/z7xpkw3538z71904cdqhztv00000gn/T//ccGJEHr7.s:24:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/mp/z7xpkw3538z71904cdqhztv00000gn/T//ccGJEHr7.s:24:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
Undefined symbols for architecture x86_64:
"std::basic_ostream<char, std::char_traits<char> >::operator<<(double)", referenced from:
_main in ccpjcybF.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccpjcybF.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccpjcybF.o
"std::cout", referenced from:
_main in ccpjcybF.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我该如何解决这个问题?
更新:
遵循答案,现在我使用了g++
,即。
g++ filename.cpp -o filename.out
现在,我收到以下错误:
/var/folders/mp/z7xpkw3538z71904cdqhztv00000gn/T//ccJjEuJy.s:24:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/mp/z7xpkw3538z71904cdqhztv00000gn/T//ccJjEuJy.s:24:11: note: change section name to "__text"
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
您正在用gcc
编译C源代码。
这就是问题,您应该使用g++
。
您可以尝试使用g++
:
g++ filename.cpp -o filename.out
或苹果的clang++
:
clang++ filename.cpp -o filename.out