I wrote a simple program fabs.cto display the absolute value of a floating point number.
fabs.c
#include <stdio.h> #include <math.h> int main(void) { float f; printf("Enter a floating-point number: "); scanf("%f", &f); printf("Its absolute value is %f.\n", fabs(f)); return 0; }
fabs () is required to include a header file math.h, but I compiled without an option -lm.
math.h
-lm
gcc fabs.c -o fabs
He even man fabssays link with -lm. But I do not know why I can compile it without -lm.
man fabs
link with -lm
, -lm, -lm. , , ( gcc). , . , ( fabs, ).
fabs
, , , " X", " A, B, C, , X, , , , , D B, , , A ( )".
-lm, , . , , , .
gcc . printf, gcc fabs. , -fno-builtin, gcc:
printf
-fno-builtin
yoones@laptop:/tmp/toto$ gcc -fno-builtin main.c /tmp/cc5fWozq.o: In function `main': main.c:(.text+0x37): undefined reference to `fabs' collect2: error: ld returned 1 exit status
nm :
nm
yoones@laptop:/tmp/toto$ nm ./a.out 0000000000600a18 B __bss_start 0000000000600a18 b completed.6661 0000000000600a08 D __data_start 0000000000600a08 W data_start 00000000004004b0 t deregister_tm_clones 0000000000400530 t __do_global_dtors_aux 00000000006007e8 t __do_global_dtors_aux_fini_array_entry 0000000000600a10 D __dso_handle 00000000006007f8 d _DYNAMIC 0000000000600a18 D _edata 0000000000600a20 B _end 0000000000400644 T _fini 0000000000400550 t frame_dummy 00000000006007e0 t __frame_dummy_init_array_entry 00000000004007d8 r __FRAME_END__ 00000000006009d0 d _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 0000000000400408 T _init 00000000006007e8 t __init_array_end 00000000006007e0 t __init_array_start 0000000000400650 R _IO_stdin_used U __isoc99_scanf@@GLIBC_2.7 w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable 00000000006007f0 d __JCR_END__ 00000000006007f0 d __JCR_LIST__ w _Jv_RegisterClasses 0000000000400640 T __libc_csu_fini 00000000004005d0 T __libc_csu_init U __libc_start_main@@GLIBC_2.2.5 0000000000400576 T main U printf@@GLIBC_2.2.5 00000000004004f0 t register_tm_clones 0000000000400480 T _start 0000000000600a18 D __TMC_END__
Source: https://habr.com/ru/post/1686326/More articles:Angular 2/4: difference between scripts.bundle.js and vendor.bundle.js - angularEfficient memory with centralized sparse SVD / PCA (in July)? - sparse-matrixasync waiting while loading image - javascriptPuppeteer debugging - javascriptIs there a way to change the module path and add modules for a JShell program instance? - javaScikitLearn Regression: The X design matrix is ββtoo large for regression. What am I doing? - pythonAccounts disappear in Xcode 9 - xcodeFailed to remove python package from pypy virtualenv on windows in design mode - pythonUNEPT PEER DEPENDENCY jquery @> = 3.0.0 and popper.js@^1.11.0 - jqueryPassing a component in the details using the children method - javascriptAll Articles