I'm trying to learn C++ and was trying to solve a problem where given a number of steps and the number of possible ways you can climb up the steps, give all the permutations of the possible ways you can climb up the steps. So for example, if there are 5 steps to climb and I can either move up 1 step at a time, 2 steps at a time or 3 steps at a time, I would need to print out all permutations of 1, 2 and 3 that add up to 5: [1, 1, 1, 1, 1]
, [1, 1, 1, 2]
, ....
I started with this code (it's not done yet), but I get this error:
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
I really don't get what I'm doing wrong. I'd appreciate it if I could get some help. Thanks!
#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 link-editor's -z defs option can be used to force a fatal error if any undefined symbols remain. This option is recommended when creating any shared objects. Shared objects that reference symbols from an application can use the -z defs option, together with defining the symbols by using an extern mapfile directive.
Why Is the Undefined Symbols for Architecture x86_64: Error Happening? This error is happening due to the lack of included values inside the declared statements in your code. The browser is going to render the information incorrectly and show this error, especially if you are working with Main and Similarity tools.
a, you can easily fix the problem. Remove the current reference to library. a in your app project in Project -> Target -> Build Phases -> Link Binary With Libraries. Open the library's project in Xcode and change the Valid Architectures to arm64 armv7 armv7s.
Your compiler error is coming from the fact that your signature for the forward declaration of _num_steps
does not match the signature of your definition of _num_steps
. the type of steps_list
does not match
Change your prototype line to:
void _num_steps(int amount, vector<int> possible_steps, vector<int> steps_list, vector<vector<int>> result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With