简体   繁体   English

链接器错误:ld:找不到体系结构x86_64的符号

[英]Linker error : ld: symbol(s) not found for architecture x86_64

I'm trying to compile the following bit of code using the terminal on my Mac. 我正在尝试使用Mac上的终端来编译以下代码。 The code is written in Sublime Text. 该代码用Sublime Text编写。

#include <iostream>
#include <fstream>
#include <vector> 
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <string> 
#include <locale> 
#include <cstdlib>

using namespace std;

void parse(string s, vector<string> q);

int main(int argc, char* argv[])
{

    cout << argv[1] << endl;
    cout << argv[2] << endl;
    cout << argv[3] << endl;
    cout << argv[4] << endl;

    int h = stoi(argv[1]);
    int k, c;
    string query;
    vector<string> query_words;
    if(!strcmp(argv[2], "-k"))
    {
        k = stod(argv[3]);
    }

    if(!strcmp(argv[2], "-c"))
    {
        c = stod(argv[3]);
    }


    query = argv[4];
    parse(query, query_words);

    return 0;
}


void parse(string s, vector<string> &q)
{

    string x;
    for(size_t i = 0; i < s.length(); i++)
    {
        string temp;
        if(s[i] == '_')
        {
            s[i] = ' ';
        }

        if(!isalnum(s[i]) && s[i] != ' ')
        {
            temp = s.substr(i+1, s.length() - i-1); 
            x = s.substr(0, i) +  temp;
            s = x;
            i--;
        }
    }

    int start_subString = 0;
    for(size_t i = 0; i < s.length(); i++)
    {
        if(s[i] == ' ')
        {
            string temp = s.substr(start_subString, i - start_subString);
            start_subString = i+1;
            q.push_back(temp);

        }

        if(i+1 == s.length())
        {
            string temp = s.substr(start_subString, i + 1 - start_subString);
            q.push_back(temp);

        }
    }


}

I attempt to compile using the following line: 我尝试使用以下行进行编译:

g++ -std=c++11 hits.cpp -o hits

and this results in the following error: 并导致以下错误:

Undefined symbols for architecture x86_64:
  "parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >)", referenced from:
      _main in hits-d8b25c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

You declare: 您声明:

void parse(string s, vector<string> q);

So, that's what it calls. 因此,这就是所谓的。 Unfortunately, you define: 不幸的是,您定义:

void parse(string s, vector<string> &q)

That's not the same function, which is why the linker can't find the function it is looking for — you've not defined it. 那是不一样的函数,这就是链接器找不到所要查找的函数的原因-您尚未定义它。 Most likely, you just need to fix the declaration. 最有可能的是,您只需要修复声明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ ld:找不到体系结构x86_64的符号”上的“铛:错误:链接器命令失败,退出代码为1” - “clang: error: linker command failed with exit code 1” on “ld: symbol(s) not found for architecture x86_64” ld: 找不到体系结构 x86_64 的符号 - 错误 - ld: symbol(s) not found for architecture x86_64 - Error ld:找不到架构x86_64错误的符号 - ld: symbol(s) not found for architecture x86_64 error ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看 - ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) - ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) OpenCV 3 的“ld:未找到架构 x86_64 的符号” - "ld: symbol(s) not found for architecture x86_64" for OpenCV 3 ld:在Mac上找不到架构x86_64的符号 - ld: symbol(s) not found for architecture x86_64 on mac ld:找不到架构 x86_64 qt 的符号 - ld: symbol(s) not found for architecture x86_64 qt g ++ ld:找不到架构x86_64的符号-没有更具体的错误消息 - g++ ld: symbol(s) not found for architecture x86_64 - without more specific error message C ++库编程错误:找不到架构x86_64的ld:符号 - C++ Library programming error: ld: symbol(s) not found for architecture x86_64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM