Cannot use pow(), sqrt() in C | Undefined reference to pow collect2 error: ld returned 1 exit status
HTML-код
- Опубликовано: 22 авг 2024
- Cannot use pow(),sqrt() in C Undefined reference to pow collect2 error: ld returned 1 exit status | Fix Undefined reference to function collect2 error: ld returned 1 exit status
This video Explains how to resolve undefined reference to sqrt() or pow() error. Keep this in mind, especially when using math.h header file in Linux. Remember to add the (-lm) argument to ensure your code connects to “libm.a” (maths library). Here is how you can write the command to pass (lm) argument and successfully compile your program.
On Linux, when you include the math.h header in the program then you are adding the pow() function declaration and not its definition. The libm.a library file holds the detailed definition for the function. A library is a collection of various object files.
The path to libm.a file on Linux is ‘/usr/lib/libm.a’. Therefore, you must pass this path to the library location with the argument as you compile your program on the terminal. Therefore, you have to link your C program with the library to make sure calls to functions such as pow() are solved. You can pass the path to the library in two ways.
First, you can provide the full path to the library file as follows:
$ gcc -o ExampleProgram ExampleProgram.c -lm
thank you saar
Happy to help😊
Thank you so much bhai 🫂
You are welcome
Didn't work for me {parrot os}
Have you tried restarting
@mjhacks6443 Yeah, it did work now. My file wasn't found at that time, but now it is found after a couple of struggles . Ty anyway
sir please make video on --> When I type mongosh on terminal on my ubuntu system i got "MongoNetworkError : connect ECONNREFUSED"
PLEASE SOLVE MY PROBLEM SIR MY HUMBLE REQUEST TO YOU 😢
Hello brother,
I saw your issue and found a solution. I have made a video about it. you may check it out.
video link: ruclips.net/video/C0Dthf4wpqw/видео.html
@@mjhacks6443 thanks sir 🙏
Hi bro.Just wondering why did you posted the comment in a vscode C video?