Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode C++ Error "linker command failed with exit code 1"

I am a beginning programming student.

Here I have written a simple "sum of two numbers" program in Xcode using C++.

//preprocessor directive
#include <stdio.h>

//local declarations

int main (void)
{
//declare variables
int n1, n2, sum;

//input prompts
printf("This program finds the sum of two numbers. Enter your first number.\n");
scanf("%d" , &n1);

printf("Enter another number.\n");
scanf("%d" , &n2);

//process
sum=n1+n2;

//output
printf("The sum is %d." , sum);

return 0;

}

As far as I can tell, my syntax is accurate, however, when I try to build the program, I get this error code:

"Apple Mach-O Linker (Id) Error. Linker command failed with exit code 1 (use -v to see invocation)"

I have been unable to solve this by reading other Q's and A's.

Any proposed solution? It would be greatly appreciated!!

like image 808
the5string Avatar asked Aug 25 '26 23:08

the5string


1 Answers

Your error is incomplete. You need to use -v to see invocation (as suggested) or you need to check your log for more details as the error 'Linker command failed with exit code 1' is usually followed by the more detailed error.

So to find more details, in Xcode click on the error under Buildtime and choose Reveal in log. This should give you extra hint. Without any specific error, it's difficult to know what's the problem.

like image 139
kenorb Avatar answered Aug 28 '26 14:08

kenorb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!