undefined reference to sqrt C/C++ Origin: Application & API OSI layer 7 · Application Last updated 28 Nov 2026

undefined reference to `sqrt' / `pow' / `sin' — missing -lm

The math library is not linked, so libm functions are unresolved.

Exact message you may see undefined reference to `sqrt'undefined reference to `pow'undefined reference to `sin'
Seen on: C/C++ Linux

Meaning

On Linux with GCC, libm is separate from libc. Put -lm after the object files.

Common causes

  • -lm missing
  • -lm placed before the sources

⚡ Quick fix

  1. Add -lm at the end of the command
  2. In CMake use target_link_libraries(app m)

Detailed fix by platform

GCC

  1. gcc main.c -o app -lm

How to diagnose

  1. Order — -lm after sources?
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

cannot find -l — /usr/bin/ld: cannot find -lssl: No such file or directory (C/C++)cannot find -lfile in wrong format — ld: file in wrong format / skipping incompatible libfoo.so when searching (C/C++)file in wrong formatLNK1112 — MSVC: fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64' (C/C++)LNK1112LNK2001 — MSVC: error LNK2001: unresolved external symbol / LNK1120: unresolved externals (C/C++)LNK2001recompile with -fPIC — relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC (C/C++)recompile with -fPICundefined reference to — C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status (C/C++)undefined reference toundefined reference to clock_gettime — undefined reference to `clock_gettime' / `shm_open' / `timer_create' — missing -lrt (C/C++)undefined reference t…undefined reference to dlopen — undefined reference to `dlopen' / `dlsym' — missing -ldl (C/C++)undefined reference t…undefined…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.