T-Roy Teelucksingh
T-Roy Teelucksingh

Reputation: 1

C++ compiler error in CodeBlocks & Xcode

I'm currently learning to become a programmer and while I was learning I came across a bit of a problem. This program doesn't run and gives me an error

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Why is this and how do I fix it and prevent it from happening again?

#include <iostream>
using namespace std;

void Fav();
int main()
{
    Fav();
    return 0;
}
void Fav(int x)
{
    cout<<"Troy's Favorite Number is \n"<<x;
}

Upvotes: 0

Views: 20

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117971

The declared function and defined function are different. They are therefore different functions, the former of which is never defined, even though it is called in main

void Fav();      // Declared
void Fav(int x)  // Defined

You need to change the signature of the declared function to matche the declared and called function

void Fav(int x);
int main()
{
    int x;
    cin >> x;
    Fav(x);
    return 0;
}

void Fav(int x)
{
    cout<<"Troy's Favorite Number is \n" << x;
}

Upvotes: 1

Related Questions