changing built in math function


I want to provide a new sqrt function to be used instead ob libm one. But CLion uses the libm one instead of mine

I have observed that target_link_libraries is not longer necessary to include libm in linking

Is there any way to exclude -lm for linking?  Do I have to change my function name (it works fine If I do so)?





On what OS do you use CLion?

What toolchain do you use (`File | Settings | Build, Execution, Deployment | Toolchains`)?

What includes do you have in this source file? 


Hi Anna!

The SO is MacOS Ventura 13.2

toolchain = Default

Only stdio.h. No need to include math.h nor specify that the program must be linked with libm

If I add a new function sqrt(), I can't use it. The one contained in libm is used in any case. 

Thank you 


On my side (CLion on macOS with the default toolchain) if I create a default "Hello, World!" project (`File | New Project` > `C Executable` > `Create`) and add just double a = sqrt(4); to it, the sqrt function is marked as error with the following text:

And compilation also fails:



Hi Anna:

Yes, you are right. It happens the same to me.

But if I add a new function sqrt to the program, when I call such a function, the one executed is the original one, the one contained in libm, not the new one I have defined (even though no math.h include nor libm.a linking indications) 

does it happen the same to you? If so, is there any way to use my sqrt function instead of the libm? I know that I could change its name, and everything would work fine. But the behavior is strange to me, and I would like to get an explanation.




Please sign in to leave a comment.