Reputation: 8554
I am running the following code in c++ in Xcode on Mac
int fibo(int x)
{
if (x==1||x==2)
return 1;
else
return fibo(x-1)+fibo(x-2);
}
and receiving this error cannot know why.
undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can somebody help me with?
Upvotes: 1
Views: 564
Reputation: 163
You should to implement main() function.
The main function is called at program startup after initialization of the non-local objects with static storage duration. It is the designated entry point to a program that is executed in hosted environment (that is, with an operating system). The entry points to freestanding programs (boot loaders, OS kernels, etc) are implementation-defined. http://en.cppreference.com/w/cpp/language/main_function
#include <iostream> // for std::cout
int fibo(int x)
{
if (x==1||x==2)
return 1;
else
return fibo(x-1)+fibo(x-2);
}
int main()
{
int x = 1;
int result = fibo(x);
std::cout << "Result: " << x; // Printing result
return 0;
}
Upvotes: 0
Reputation: 4770
You need to define a main
function. That's first function that gets called to "start" your program.
Add this to your file:
int main()
{
fibo(10); // calls your function with
}
Upvotes: 1