[英]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.