I added the header <math.h>
to a project to start to test out the fmod function, which returns a fractional part of float division. I have more questions on that, but i'll save it for another question.
So after adding the header and using the function, no lint errors went off then I try to build the program.
I get this error:
/usr/bin/ld: CMakeFiles/main.dir/main.c.o: undefined reference to symbol 'fmod@@GLIBC_2.2
.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
okay so getting better at reading c errors i noticed ld which means linker, okay fine.
Next I start googling the error and I find the answer. I need to add the linker flag -lm
why? I don't know so I start searching google what that linker flag means and I didn't really find any answers. Went back to SO and found this question and answer.
these were the quotes under the main question.
Read the library documentation ... – pmg
...and then google. – Ori Pessach
linking semantics vary across operating systems and compilers. We'd need a lot more detail to make any useful contributions. – radical7
pkg-config seems okay if I have a one off file but as a project grows if you get these linker errors it becomes hard to figure out what's wrong.
Another answer was read the docs. I went back to google and came across this documentation about math.h
but nowhere does it say anything about the actual linker flags to use.
So my question what documentation was @pmg talking about in his reply? What's a general purpose way to find this documentation on my system just in case I cannot use google for whatever reason? Especially since I have the files on my computer and able to include them.