Undefined symbols for architecture arm for

1.1k Views Asked by At

I am new to C++, and trying to use get_string, but I am not sure what I writing wrong that is creating an error.

The code I have is the following:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
   string name = get_string("What's your name? ");
   printf("hello, %s\n", name);
}

and it keeps saying the following error:

Undefined symbols for architecture arm64:
  "_get_string", referenced from:
      _main in hello-890d43.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello] Error 1

Does any one know what I am doing wrong?

I expected the code take an input and print out hello, (your input).

3

There are 3 best solutions below

0
Gaëtan Bloch On

The same thing happened to me when trying to use the cs50 C library on my local Mac with M1 chip.

Even after installing the library as described here: https://cs50.readthedocs.io/libraries/cs50/c/ It still didn't work.

The problem is coming from the fact that the make command here doesn't include the link command by default.

Assuming your source file is named hello.c instead of just doing:

make hello

You have to enter the following in your terminal in order to compile:

clang hello.c -o hello -lcs50

Afterwards, when running the executable, it works as expected:

./hello
1
Sergio Teixeira On
make hello LDLIBS="-lcs50"

LDLIBS to include the cs50 library

0
ZERO On

Undefined symbols for architecture arm64: "_get_string", referenced from:

Assuming you installed the latest CS50 Library. If not, download it, open the terminal, type cd, then hit space, and drag the folder onto the terminal. You should have a file path displaying. Run the "sudo make install" command, type in your Mac password, and the file should install.

Open VSCode and type clang hello.c -o hello -lcs50. Once you hit enter type ./hello.

The code should now run without any errors!