0

I tried looking everywhere to see if theres an answer but it seems that people have encountered the similar problem but none of the solutions that I read have worked.

Im using gcc as my compiler

I am familiar with c++ but never encountered a problem like this on c++, but, Im just trying to do a simple printf and scanf for user input and printing out the results.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1, num2;

    printf("Enter two integers: \n");
    scanf("%d%d",&num1,&num2);

    printf("your two integers are: %d and %d \n", num1,num2 );

return 0;
}

the error that I get in the terminal:

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)

thank you in advanced!

6
  • What is the exact command you are using? Commented Sep 7, 2018 at 1:33
  • 1
    The error message mentions clang. Are you sure you're using gcc? Commented Sep 7, 2018 at 1:35
  • gcc -c main.c , gcc -o main main.c, and i tried gcc -o main main.o ,still same error Commented Sep 7, 2018 at 1:36
  • @sneep gcc might be a symlink to clang, for compatibility. Commented Sep 7, 2018 at 1:39
  • can you tell the gcc version. gcc --version Commented Sep 7, 2018 at 1:39

1 Answer 1

1

I think I figured it out, and it might have been an outdated gcc, so I just typed these commands in the terminal and it fixed it.

brew update

brew install gcc

brew cleanup

Thank you for your help. Honestly I am not sure if it was that fixed it but that that is the only thing that I ran.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.