Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does clang command option -lm mean?

Tags:

clang

I found someone says that -lm means linking to the math library.
I want to figure out the meaning by using build-in help in the terminal.
So I run the $ clang --help
I don't find any stuff related to -l or -m
How can I get the meaning of -lm with the self-help terminal?

like image 221
smail vili Avatar asked Nov 16 '25 05:11

smail vili


1 Answers

The -l{name} flag tells the linker to link against lib{name}. So -lm links against libm, the c math library.
This isn't a flag to the clang compiler but passed to the linker, which is why you won't find it with clang --help or man clang.
If you run clang with the --verbose flag you will see the invocation of the linker (in my case /usr/bin/ld) as the last step.
By running man ld or ld --help (or whichever linker your clang version is using) you will find the documentation.
Keep in mind that not all flags are passed to the linker in this way (-l is probably passed for compatibility with the gcc compiler as melpomene said). To make sure an option is passed, use the -Wl option of clang.

like image 64
cype Avatar answered Nov 17 '25 21:11

cype



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!