user3341411 user3341411 - 5 months ago 55
C Question

C in Xcode cs50.h issues

I am trying to follow along with the cs50 course online in Xcode. I have imported the cs50 header file. I can use

but I am still getting errors when calling
. Error reads:

Apple Mach-O Linker (Id) Error "_GetInt", referenced from:

Any help is of course greatly appreciated. Thank you.


You need to add cs50.c to your build target in XCode. To do this, select "Add files to …" from the File menu, and tick the box for all the targets. If you add more build targets, select the cs50.c file and in the right-side inspector pane tick the box for the new target.

Note that you can also use Terminal to use command-line as described in the course instructions. Using the example code:

#include <stdio.h>
#include "cs50.h"
int main(void) {
    printf("Input number... \n");
    int x = GetInt();
    printf("You typed the number %d\n", x);
    return 0;

You can build and run it as follows (assuming the code is foo.c in the same directory as cs50.h and cs50.c):

$ clang -o foo foo.c cs50.c
$ ./foo
Input number...
You typed the number 5