Monday, October 31, 2011

Solving Gcc Math.h Linking Problem in Eclipse

If you use Eclipse/gcc and have functions that need the math.h library, you may find out that the linker can't find functions like sqrt or pow and signal it like this:

undefined reference to `pow'    Matrix.c    /TzUtils/Sources    line 152    C/C++ Problem
undefined reference to `pow'    Matrix.c    /TzUtils/Sources    line 204    C/C++ Problem

This thing happens because the library which contains math.h is not linked by default. To link it you will need to add the extra flag -Im.

In Eclipse this can be done by:
  1. Right click on your project in Project Explorer and select Properties.
  2. Go to C\C++ Build -> Settings -> Tool Settings -> Gcc Linker -> Libraries and click on green plus button to add a new library. When the dialog pops up, write m, and Eclipse will automatically add the -Im flag.



2 comments:

Got a question regarding something in the article? Leave me a comment and I will get back at you as soon as I can!

Related Posts Plugin for WordPress, Blogger...
Recommended Post Slide Out For Blogger