Cannot use pow(), sqrt() in C | Undefined reference to pow collect2 error: ld returned 1 exit status

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

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 😢

shyboy-brqk