Question

I am trying to follow along with the cs50 course online in Xcode. I have imported the cs50 header file. I can use printf but I am still getting errors when calling GetInt. Error reads:

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

Any help is of course greatly appreciated. Thank you.

Was it helpful?

Solution

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...
5
You typed the number 5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top