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

Комментарии • 11

  • @tawhidkhan5151
    @tawhidkhan5151 4 месяца назад +1

    thank you saar

  • @antrikshyagupta
    @antrikshyagupta 4 месяца назад +1

    Thank you so much bhai 🫂

  • @JazLegacy
    @JazLegacy 2 месяца назад +2

    Didn't work for me {parrot os}

    • @mjhacks6443
      @mjhacks6443  2 месяца назад +1

      Have you tried restarting

    • @JazLegacy
      @JazLegacy 2 месяца назад +2

      @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

  • @shyboy-br1qk
    @shyboy-br1qk 6 месяцев назад +1

    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 😢

    • @mjhacks6443
      @mjhacks6443  6 месяцев назад

      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

    • @shyboy-br1qk
      @shyboy-br1qk 6 месяцев назад +1

      @@mjhacks6443 thanks sir 🙏

    • @mjhacks6443
      @mjhacks6443  6 месяцев назад

      Hi bro.Just wondering why did you posted the comment in a vscode C video?