为什么我在以下代码中出现clang错误?

时间:2017-07-30 09:02:14

标签: c++

#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;
}

我编写了上面的代码,它只计算给定数组中的最大非负子数组。当我尝试编译上面的内容时,我收到以下错误:

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

这个错误非常神秘,我无法弄清楚我在代码中出错的地方。感谢

1 个答案:

答案 0 :(得分:0)

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