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!
HP ProLiant Xeon E3-1220L V2 16 GB RAM 2.30 GHz MicroServer Gen8 NO DRIVES
$174.99
HP PROLIANT MICROSERVER MICRO SERVER HSTNS-5151 T4 Used.
$45.00
HP ProLiant HSTNS-5151 Micro Server 8GB RAM No Drives/Key/Caddies *READ*
$94.99
Supermicro Server Tower Xeon BOOTS E5-2620 v4 2.10GHz 64GB RAM NO HDD NO OS
$199.99
SuperMicro Server 505-2 Intel Atom 2.4GHz 8GB RAM SYS-5018A-FTN4 1U Rackmount
$202.49
HPE ProLiant MicroServer Gen10 Plus v2 Ultra Micro Tower Server - 1 x Intel Xeon
$846.19
SUPERMICRO CSE-512 AMD Opteron Processor 6128, 32GB DDR3 RAM NO HDD
$90.00
Supermicro 5018A-FTN4 Rack Server - Black
$125.00
2U 12 Bay SAS3 SuperMicro Server 6028U-TR4T+ W/ X10DRU-i+ Barebone 12 Caddy RAIL
$299.00
1U Supermicro Server 10 Bay 2x Intel Xeon 3.3Ghz 8C 128GB RAM 480GB SSD 2x 10GBE
$297.00