. Advertisement .
..3..
. Advertisement .
..4..
I get the error message:
Undefined symbols for architecture x86_64:
"_num_steps(int, std::__1::vector<int, std::__1::allocator<int> >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >)", referenced from:
num_steps(int, std::__1::vector<int, std::__1::allocator<int> >) in num_steps-FTVSiK.o
ld: symbol(s) not found for architecture x86_64
Has anyone ever faced this problem? How to troubleshoot the “undefined symbols for architecture x86_64 c++.” The problem appears when I try to operate the following program:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
//prototypes
void _num_steps(int amount, vector<int> possible_steps, vector<vector<int>> steps_list, vector<vector<int>> result);
int sum(vector<int> steps_list);
void num_steps(int amount, vector<int> possible_steps);
//
//
//
void num_steps(int amount, vector<int> possible_steps) {
vector<vector<int>> result;
_num_steps(amount, possible_steps, {{}}, result);
//print_result(result);
}
int sum(vector<int> steps_list) {
int sum_of_steps(0);
for (auto step: steps_list) {
sum_of_steps += step;
}
return sum_of_steps;
}
void _num_steps(int amount, vector<int> possible_steps, vector<int> steps_list, vector<vector<int>> result) {
if (sum(steps_list) == amount) {
result.push_back(steps_list);
return;
}
else if (sum(steps_list) >= amount) {
return;
}
for (auto steps: possible_steps) {
auto steps_list_copy = steps_list;
steps_list_copy.push_back(steps);
_num_steps(amount, possible_steps, steps_list_copy, result);
}
cout << "yeah" << endl;
return;
}
int main(int argc, char* argv[]) {
num_steps(5, {1, 2, 3});
return 0;
}
The cause:
Because the signatures of your forward declaration of
_num steps
and_num steps
definition do not match, this causes a compiler error. It is not compatible with the type ofsteps_list
.Solution: To fix the error “undefined symbols for architecture x86_64 c++”, replace the line in your prototype with:
The arguments list for a function declaration must contain the same types as its definition.
Yours don’t match.
Declaration:
Definition: