It's a link-time error; you need to add '-lm' to your command line in order to pull in the math library.
I started using Knoppix (3.3) some days ago, mainly to write C-programs (but I'm liking it more&more, also for the rest of the package!).
I am, however, experiencing problems in compiling programs that use <math.h>. F.i.:
Won't compile, giving:Code:#include <stdio.h> #include <math.h> int main(){ printf("%f\n",sqrt(123.456)); return 0; }
Can someone explain what's going wrong? I have no problems including <ctype.h> or <string.h>.Code:knoppix@ttyp0[test]$ gcc test.c /tmp/cc8Hr3am.o(.text+0x1a): In function `main': : undefined reference to `sqrt' collect2: ld returned 1 exit status
I'm a complete Linux noob, so please help me...
It's a link-time error; you need to add '-lm' to your command line in order to pull in the math library.
Thx very much! It worked!
Are there more problems to be expected when including standard header files? Is -lm always enough to cure these kind of linking problems?
And more important: where can I find info on these matters?
Thx in advance.
These are not problems, just the way the C compiler works on pretty much every unix system. -lm is a shortcut meaning you want the linker to look in standard places for a library called libm.a. On linux, tens of libraries live under /usr/lib, amongst which the default libc.a. If you wanted to link against say libcups.a, you could similarly specify -lcups. If you want to see what's in a library , use ar (eg "ar -tvf /usr/lib/libm.a").
As to where to look for information, I'm afraid the references I might give you would be embarassingly outdated (hints: Kernighan & Richie, Kernighan & Pike, Rochkind, Stevens). Just google for "unix programming". Have fun ... and be prepared for what might become a long journey!
Thanks again!
I'm not afraid of a long journey!

GIGABYTE A520M DS3H AC AMD AM4 Motherboard mATX
$59.99
GIGABYTE Z790 AORUS ELITE AX LGA 1700 Intel Z790 ATX Motherboard with DDR5
$189.99
Intel H310 LGA1151 8-9th Gen DDR4 M.2 NVMe mATX Motherboard IO Shield Battery
$54.99
ASUS PRIME Z890-P WIFI Z890 LGA 1851 ATX motherboard, Intel® Core™ Ultra Series
$235.99
GIGABYTE B365 HD3 LGA1151 Intel 9th Gen motherboard
$59.99
MSI B550M PRO-VDH Micro-ATX Motherboard - AMD AM4, Ryzen 5000/4000/3000 Ready, P
$71.49
Asus Prime B660M-A AC D4 Motherboard Intel LGA 1700 14th 13th 12th Gen DDR4
$79.99
Intel H81 Motherboard M.2 NVMe LGA 1150 mATX w/ IO Shield (Random Slot Color)
$29.90
ASUS PRIME Z490-V Motherboard Intel Z490 10th gen DDR4 LGA 1200 ATX w/ IO Shield
$84.99
Gigabyte GA-B85M-D3H Motherboard
$54.99