So I'm currently new to C right now, and I just downloaded the cs50 library. I tried to make an input by using get_int(), but it's not working. Here's my code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int i = get_int("Input: ");
printf("Output: %i\n", i);
}
This is the error that I got
cc calculator.c -o calculator
Undefined symbols for architecture x86_64:
"_get_int", referenced from:
_main in calculator-225c65.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [calculator] Error 1
Related
This question already has an answer here:
CS50 get_string error linker command failed with exit code 1
(1 answer)
Closed 13 days ago.
I have the following code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int x = get_int("whats x? ");
int y = get_int("whats y? ");
if (x < y)
{
printf("x is less than y\n");
}
}
It keeps giving me this error
moutarrjallow#Moutarrs-MBP cclang % make ccompare
cc ccompare.c -o ccompare
Undefined symbols for architecture x86_64:
"_get_int", referenced from:
_main in ccompare-91f0e5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ccompare] Error 1
You need to link with the cs50 library by adding the -lcs50 to above. In your Makefile you can probably do that by setting LDLIBS := -lcs50.
I have this code:
#include <stdio.h>
#include <termcap.h>
#include <stdlib.h>
int main() {
char *termtype = getenv("TERM");
int li = tgetnum("li");
printf("%d", li);
return 0;
}
I can't compile it because I get
Undefined symbols for architecture x86_64:
"_tgetnum", referenced from:
_main in main-11560e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why is it happening?
MacOS Catalina
I'm trying to reproduce the code of the book Effective C: An Introduction to Professional C Programming by R. Seacord
#include <stdio.h>
void swap(int, int); // defined in Listing 2-2
int main(void) {
int a = 21;
int b = 17;
swap(a, b);
printf("main: a = %d, b = %d\n", a, b);
return 0;
}
When I compile the code on my MacOS 10.15.7 with gcc swap.c, I get the following error:
Undefined symbols for architecture x86_64:
"_swap", referenced from:
_main in swap-315897.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What shall I do to correct it?
I realize this has probably been answered but I just cannot find it. When using "make" to compile the following file:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
// get line of text
string s = GetString();
// print string, one character per line
for (int i = 0; i < strlen(s); i++)
{
char c = s[i];
printf("%c\n", c);
}
return 0;
}
I get the following message:
$ make example
cc example.c -o example
Undefined symbols for architecture x86_64:
"_GetString", referenced from:
_main in example-iPNXBe.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [example] Error 1
Judging from the cs50 page you probably need something like -lcs50 at the end of the cc command.
Or you can just use the cs50.o object file and link with it.
cc example.c cs50.o -o example
I'm using the gsl library in a c code. Everything goes fine but when i use the command gsl_linalg_cholesky_invert the terminal shows the following message:
Undefined symbols for architecture x86_64:"_gsl_linalg_cholesky_invert", referenced from:
_main in cc4eefuQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
A code example is the following.
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_linalg.h>
#include <math.h>
void main()
{
gsl_matrix * A = gsl_matrix_calloc (2,2);
gsl_matrix_set(A,0,0,1);
gsl_matrix_set(A,0,1,0.5);
gsl_matrix_set(A,1,0,0.5);
gsl_matrix_set(A,1,1,1);
gsl_linalg_cholesky_decomp(A);
gsl_linalg_cholesky_invert(A);
}
If i comment out the line gsl_linalg_cholesky_invert(A);, everything goes fine.
I compile the code with the following command:
gcc-mp-4.7 wrapnorm.c -o wrapnorm -lgsl -l gslcblas -lm
with a macbook pro with mountain lion and gsl version 1.9.
Thanks