the5string
the5string

Reputation: 31

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!!

Upvotes: 3

Views: 2019

Answers (2)

kenorb
kenorb

Reputation: 166399

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.

Upvotes: 1

Wojtek Surowka
Wojtek Surowka

Reputation: 20993

This error is normally displayed if you have other errors in your source code. If you copy pasted the code directly, there is an x before the opening brace in main.

Upvotes: 0

Related Questions