Pow function needed using Studio 7

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I need to use the pow function in a program. Although I have used #include<math.h> and  #include<tgmath.h>  and  I do  get a response from the "Goto implementation" in that it appears to find the library , on compiling I get "implicit declaration of function 'pow' as if the compiler cannot find the function in either library.  Although I have found this problem in old postings, none of the answers seem appropriate to use within Studio 7.  My version of Studio 7 is pretty up to date: vers. 1709.3.1

 

Any help would be much appreciated. Mike

This topic has a solution.
Last Edited: Tue. May 25, 2021 - 02:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
#include "sam.h"
#include <math.h>

int main(void)
{
    double a = pow(2, 2);
}

This compiles fine for me... Please show us your code (and what device you're using), or attach the project

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.  Thank you for this.  I realize where I was going wrong, or I have now found a work around.  I modularise my programs so that for example I am porting an Arduino library for the MPU 9250 Motion Tracking device into a .c source file and an .h source file usable by a SAMD21.

 

I had put the #include <math.h> in the main file which is a reasonably logical place to put it, but I have now put it in the MPU9250 .c file where pow is now working.  I am spelling this out in case anybody else has the same problem.

 

By the way, would anybody else be interested in having an area where "Atmel" versions of libraries for complicated chips like the MPU9250 could be shared?

 

Mike

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mikefw wrote:
I had put the #include <math.h> in the main file which is a reasonably logical place to put it

Not if the place you're using pow() isn't "the main file".

 

Quote:
 but I have now put it in the MPU9250 .c file where pow is now working.  I am spelling this out in case anybody else has the same problem.

This is the way that the C programming language works:  the declaration has to be visible in the same Compilation Unit (which usually means the same .c file) as the use;

Therefore, the #include needs to be in the same Compilation Unit (which usually means the same .c file) as the use.

 

When the problem is resolved, please mark the solution - see Tip #5 in my signature, below:

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. May 25, 2021 - 01:56 PM