0

I use the CS50 online IDE and I have the following error:
ex1.c:(.text+0x1b): undefined reference to `get_int'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

Code

#include <stdio.h>
#include <cs50.h>
int main(void){
    int x= get_int("Please, type an integer");
switch(x)
{
    int x= get_int("Please, type an integer");
    case1:
    printf("One!\n");
    break;
    case2:
    printf("Two!\n");
    break;
    case3:
    printf("Three!\n");
    break;
    default:
    printf("Sorry!\n");
}
}
0

How do you compile this programme?

#include <cs50.h> will only tell the compiler what the functions look like, it does not tell where their implementations are.

You would have to pass -lcs50 to tell the linker to link against the cs50 library, like clang -o ex1 ex1.c -lcs50.

As you are in the CS50 IDE, environment variables are set up so that you instead can simply do

make ex1
7
  • After I use: make ex1 I get the errors: ex1.c:7:9: error: declaration shadows a local variable [-Werror,-Wshadow] int x= get_int("Please, type an integer"); ^ ex1.c:4:9: note: previous declaration is here int x= get_int("Please, type an integer"); ^ ex1.c:8:5: error: unused label 'case1' [-Werror,-Wunused-label] case1: ^~~~~~ ex1.c:11:5: error: unused label 'case2' [-Werror,-Wunused-label] case2: ^~~~~~ ex1.c:14:5: error: unused label 'case3' [-Werror,-Wunused-label] case3: ^~~~~~ – mikeli May 7 '20 at 20:47
  • That came up because make in this environment also includes compiler arguments for stricter checks. Remove that first line inside the switch, the one that's duplicating the line before the switch. – Blauelf May 7 '20 at 20:52
  • Btw, it's case 1 with a space in between. – Blauelf May 7 '20 at 20:55
  • I removed the first line inside the switch -the duplicate- as you've suggested. Now I get the following errors. clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow ex1.c -lcrypt -lcs50 -lm -o ex1 ex1.c:7:5: error: unused label 'case1' [-Werror,-Wunused-label] case1: ^~~~~~ ex1.c:10:5: error: unused label 'case2' [-Werror,-Wunused-label] case2: ^~~~~~ ex1.c:13:5: error: unused label 'case3' [-Werror,-Wunused-label] case3: – mikeli May 7 '20 at 21:08
  • I removed the duplicate line -the first one- inside the switch. I've also added spaces after case ie. case 1, case 2 etc and now I get : clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow ex1.c -lcrypt -lcs50 -lm -o ex1 What does that mean? – mikeli May 7 '20 at 21:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .