0

I'm new to programming and wanted to try out VS Code for C++ development. I'm getting this error and I can't find a solution online how to fix:

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)

Here is my code:

#include <iostream>
using namespace std;


    long FactorielleMod(int n){
        const int c= 1000000007;
        if (n == 1 ){
            return n;
        } else {
            return ((n % c)*FactorielleMod(n-1)) % c;
        }
    }

Basically a code to compute the factorial function. Can anyone help me with this?

OMGtechy
  • 7,935
  • 8
  • 48
  • 83
  • 2
    There must be another error message before, is it complaining about a missing `main()` function? – πάντα ῥεῖ Oct 04 '20 at 18:26
  • Here is the whole errors: deRunnerFile.cpp -o tempCodeRunnerFile && "/Users/Usr/Desktop/Bureau-MBP/M2/S1/C++/projekt/helloworld/"tempCodeRunnerFile 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) – Feynman_kac Oct 04 '20 at 18:27
  • [Edit] your quesiton to put additional information please. – πάντα ῥεῖ Oct 04 '20 at 18:27
  • You mist define a function `int main()` as entry point for your executable program, that's what the error says. – πάντα ῥεῖ Oct 04 '20 at 18:32
  • You're right, thanks – Feynman_kac Oct 04 '20 at 22:54

1 Answers1

2

Exit code 1 means that an error happened. It is probably because you have no main function, which is required for every C++ program. You need something like this:

#include <iostream>
using namespace std;


long FactorielleMod(int n){
    const int c= 1000000007;
    if (n == 1 ){
        return n;
    } else {
        return ((n % c)*FactorielleMod(n-1)) % c;
    }
}

int main(){
    int a;
    cin>>a;
    cout<<FactorielleMod(a);
    return 0;
}

It will print you factorial function of inputted integer.

lejkom
  • 49
  • 6