2017-07-30 100 views
-5
#include <iostream> 
#include <map> 
#include <vector> 
#include <string> 
#include <utility> 
#include <algorithm> 
#include <stack> 
#include <queue> 
#include <climits> 
#include <set> 
#include <cstring> 

using namespace std; 
#define ll long long 
#define pb push_back 
#define mp make_pair 

int main (void) 
{ 
    int arr[] = {1,2,3,4,5,60,70,8,50,20}; 
    int mseh = 0; 
    int mssf = 0; 
    int i = 0; 
    int e = 10; 
    while (i < e) 
    { 
     mseh = mseh + arr[i]; 
     if (mseh < 0) 
      mseh = 0; 
     if (mssf < mseh) 
       mssf = mseh; 
     i++; 
    } 
    cout<<mseh<<"\n"; 
    return 0; 
} 

我写过上面的代码,它只计算给定数组中的最大非负数子数组。当我尝试编译上面,我得到以下错误:为什么在下面的代码中出现clang错误?

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) 
make: *** [1] Error 1 

此错误是非常神秘的,我无法揣摩出我的代码去错了。谢谢

+4

至少使用typedef而不是预处理器宏。不要像那样“定义类型”。 – StoryTeller

+1

你是如何编译它的?你使用了什么命令? – ZeekHuge

+0

可变和功能名称应该清晰和有意义。为下一个阅读器编写代码并易于理解,这也将减少错误。 – zaph

回答

0

这意味着你还没有链接一个合适的标准库实现,如libstdC++。在大多数情况下,你应该有一个默认链接,但很明显,这里出了问题。确切的原因将完全是环境问题。

相关问题