ld:找不到架构的符号x86_64 collect2:error:ld返回1退出状态

时间:2016-09-23 23:10:38

标签: c++

我正在运行一个非常简单的代码来解决https://leetcode.com/problems/3sum-closest/

但是,很长一段时间遇到了一个问题。我搜索谷歌,但我认为我没有找到答案。我甚至试图在一些在线模拟器中运行它,同样的问题。如果你能帮助我,我会很感激。

这段代码不正确,我只想让它先运行。 现在名称是try.cpp

我的源代码:

#include<algorithm>
#include<limits.h>
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int threeSumClosest(vector<int>& nums, int target) {
        sort(nums.begin(),nums.end());
        int ll=nums.size();
        int dif=INT_MAX;
        int res=INT_MAX;
        for(int i = 0;i<ll-2;i++){

            int l=i+1,r=ll-1;
            while(l<r){
                int newdif=nums[l]+nums[r]+nums[i]-target;
                if(abs(newdif)<dif){
                    dif=abs(newdif);
                    res=nums[l]+nums[r]+nums[i];

                }
                if(newdif<0){
                    l+=1;
                }else if(newdif>0){
                    r-=1;
                }else{
                    break;
                }
            }
        }
        return res;
    }
public:
    int main(int argc, char* argv[])
    {
        int a[3]={0,1,2};
        vector<int> v(&a[0],&a[2]);
        int b=threeSumClosest(v,3);
        cout<<b<<endl;
    }
};

我的错误:

Undefined symbols for architecture x86_64:
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int) in ccXXgrSG.o
  "std::ios_base::Init::~Init()", referenced from:
      __static_initialization_and_destruction_0(int, int) in ccXXgrSG.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

0 个答案:

没有答案