Knowee
Questions
Features
Study Tools

/usr/bin/ld: /tmp/ccBNWlLn.o: in function `main':main.c:(.text+0x87): undefined reference to `sqrt'/usr/bin/ld: main.c:(.text+0xb2): undefined reference to `sqrt'/usr/bin/ld: main.c:(.text+0xd1): undefined reference to `sqrt'collect2: error: ld returned 1 exit status

Question

/usr/bin/ld: /tmp/ccBNWlLn.o: in function main':main.c:(.text+0x87): undefined reference to sqrt'/usr/bin/ld: main.c:(.text+0xb2): undefined reference to sqrt'/usr/bin/ld: main.c:(.text+0xd1): undefined reference to sqrt'collect2: error: ld returned 1 exit status

🧐 Not the exact question you are looking for?Go ask a question

Solution

The error message you're seeing is because the linker is unable to find the definition for the sqrt function. This function is defined in the math library. When you're compiling your program, you need to link the math library using -lm.

If you're using gcc to compile your program, you should do it like this:

gcc -o program program.c -lm

Here, program.c is the name of your C file, and program is the name of the output file. The -lm at the end tells the linker to link the math library.

This problem has been solved

Similar Questions

/tmp/cc457SXT.o: In function `main':mainc-5557-1709993200.1203434.cpp:(.text+0x1f): undefined reference to `Bank::Bank()'collect2: error: ld returned 1 exit status

/home/ubuntu/Main.cpp: In function ‘int evaluateexpression(char*)’:/home/ubuntu/Main.cpp:29:12: error: ‘isdigit’ was not declared in this scope 29 | if(isdigit(token[0])){ | ^~~~~~~

home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:60:13: error: ‘exit’ was not declared in this scope 60 | exit(0); | ^~~~

Line 1037: Char 9: runtime error: reference binding to misaligned address 0xbebebebebebebec2 for type 'int', which requires 4 byte alignment (stl_vector.h)0xbebebebebebebec2: note: pointer points here<memory cannot be printed>SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_vector.h:1046:9

/home/ubuntu/Main.cpp:3:15: error: expected unqualified-id before ‘int’ 3 | char register(int weight, double height) { | ^~~/home/ubuntu/Main.cpp:3:15: error: expected ‘)’ before ‘int’ 3 | char register(int weight, double height) { | ~^~~ | )/home/ubuntu/Main.cpp: In function ‘int main()’:/home/ubuntu/Main.cpp:30:16: error: expected primary-expression before ‘register’ 30 | category = register(weight, height); | ^~~~~~~~

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.