Search code examples
cgccgeanysqrt

undefined reference to sqrt(geany)


I use Geany for C programming. When I try to build the file it gives me

error:undefined reference to sqrt.

Compile: gcc -Wall -c "%f"

Build: gcc -Wall -o "%e" "%f"

Execute: ./%e

I tried to add -lm to the build command but then it gives me

gcc error:no such file or directory.Compilation Failed.

Solution

  • The compiler and linker options with arguments must be separate, you can't compile them like you do.

    Make them separate, like e.g.

    gcc -Wall -o "%e" "%f" -lm