4 Replies Latest reply on Nov 2, 2017 9:05 AM by MartyG

    undefined reference to `sqrt'


      Why is this happened? Someone who expert on this please answer this question


      " temp_pt1000_val = -(((sqrt((-0.00232*R2) + 17.59246)) - 3.908)/0.00116); "


      Intel® Quark™ Microcontrollers AlexT_IntelMartyGqikictan94x_intelintel_adminDesktop BoardsSupport Community

        • 1. Re: undefined reference to `sqrt'

          This topic is somewhat outside of my usual areas of knowledge, but I will try to offer some useful guidance.


          It would be useful if you could please provide more details about the programs that you are developing your project with, such as the name of your C compiler program. 


          My research indicates that this error most commonly occurs when the GCC compiler program is being used.  This error may be caused if your project doesn't have a proper linkage to the math.h. library defined.


          If you are using GCC, you may be able to compile the project with the math linkage by adding -lm to the end of the compile instruction in this format:

          gcc filename.c -lm


          So if your project was called arnieproject then the compile instruction might be something like:


          gcc arnieproject.c -lm


          If you are using the Eclipse software to develop your project, you can add the linkage by going to Project > Properties > C/C++ Build > Settings > GCC C Linker > Miscellaneous.  Then add "-lm" to the "Linker Flags" text field.


          If you are using NetBeans, you can set it this way:


          - Use the Project Properties window.

          -  Select Build|Linker

          - Click on "..." in Libraries field

          - Push 'Add Standard Library...' button

          - Select Mathematics

          - Push OK, push OK, push OK

          1 of 1 people found this helpful
          • 2. Re: undefined reference to `sqrt'

            It works..thank you MartyG, I'm trying to calculate pt1000 formula from datasheet through C1000, below was the result I got .pt1000.JPG

            • 3. Re: undefined reference to `sqrt'

              MartyG one more things do you know someone from your side or if you can help what is the problem of this program, why it didn't show any value or reading from the sensor (dht22)? How to read the raw value from digital pin?


              #include "qm_gpio.h" //Calling QMSI GPIO API

              #include "clk.h"

              #include "qm_pinmux.h"

              #include "qm_pin_functions.h"



              #define PIN_DHT22 21

              #define LED_PIN_ID (QM_PIN_ID_55)

              #define PIN_MUX_FN (QM_PIN_55_FN_GPIO_21)



              //static qm_gpio_state_t {QM_GPIO_HIGH};



              uint32_t expectPulse(_Bool level) /*function to read DHT11 pulse*/


              uint32_t count = 0;

              while (qm_gpio_read_pin(QM_GPIO_0, PIN_DHT22, QM_GPIO_LOW) == level)


              if (count++ >= 100000)

              { /* 1 millisecond to read DHT11 pulse */

              return 0; /* Exceeded timeout, fail. */



              return count;




              static void pin_mux_setup(void)


              qm_pmux_select(LED_PIN_ID, PIN_MUX_FN);






              int main()


              qm_gpio_port_config_t cfg;




              uint32_t cycles[80], i; /* same cycle number as in the DHT11 library */

              uint8_t data[5];



              /* Reset 40 bits of received data to zero. */

              data[0] += data[1] += data[2] += data[3] += data[4] = 0;

              QM_PUTS("DHT22 example");





              // Act like Arduino’s pinMode

              //DHT in as O/P.

              cfg.direction = BIT(PIN_DHT22);

              qm_gpio_set_config(QM_GPIO_0, &cfg);



              qm_gpio_set_pin(QM_GPIO_0, PIN_DHT22); /* set HIGH to DHT11 pin */

              clk_sys_udelay(250000); /* 250 ms */



              //Send DHT start signal

              qm_gpio_clear_pin(QM_GPIO_0, PIN_DHT22); /* set DHT11 pin LOW */

              clk_sys_udelay(20000); /* 20 ms */



              qm_gpio_set_pin(QM_GPIO_0, PIN_DHT22); /* set DHT11 pin HIGH */

              clk_sys_udelay(40); /* 40 us */



              cfg.direction = 0;

              qm_gpio_set_config(QM_GPIO_0, &cfg); //Setting the DHT11 pin as I/P to



              //start listening from sensor

              qm_gpio_clear_pin(QM_GPIO_0, PIN_DHT22);

              clk_sys_udelay(10); //10 us





                QM_PUTS("Timeout waiting for start signal low pulse.");







                QM_PUTS("Timeout waiting for start signal high pulse.");





              for (i=0; i<80; i+=2)


                cycles[i]   = expectPulse(0);

                cycles[i+1] = expectPulse(1);




                // Inspect pulses and determine which ones are 0 (high state cycle count < low

                // state cycle count), or 1 (high state cycle count > low state cycle count).

              for (i=0; i<40; ++i)


                uint32_t lowCycles = cycles[2*i];

                uint32_t highCycles = cycles[2*i+1];



                if ((lowCycles == 0) || (highCycles == 0))


                QM_PUTS("Timeout waiting for pulse.");

                //continue ;


              data[i/8] <<= 1;



                //Now compare the low and high cycle times to see if the bit is a 0 or 1

              if (highCycles > lowCycles)


              // High cycles are greater than 50us low cycle count, must be a 1

              data[i/8] |= 1;




                // Else high cycles are less than (or equal to, a weird case) the 50us low

                // cycle count so this must be a zero. Nothing needs to be changed in the

                // stored data.




              QM_PRINTF("Receive %d %d %d %d %d\n",data[0],data[1],data[2],data[3],data[4]);

                  uint8_t TempF = data[2]*1.8+32;

                  QM_PRINTF("h : %d, t : %d, f : %d \n", data[0],data[2],TempF);

                  QM_PRINTF("h: %d , data:%d \n", data[0], data[1]);



                  //Check we read 40 bits and that the checksum matches

              if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF))







              QM_PUTS("Checksum failure!");



                return 0;


              • 4. Re: undefined reference to `sqrt'

                So you re using a DHT22 temperature sensor and are trying to read a value off the digital pin?


                I sadly know nothing about Quark microcontrollers or DHT22 temperature sensors.  I did find a case on another website though where somebody was trying to do the same thing and not succeeding.  Somebody recommended to that user that "you need a pullup resistor of between around 3.3K and 10K on the sensor data line.  Without one , it might work , but will be very unreliable."  Other advice given was to wait a couple of seconds after power-up before trying to take a reading from the digital pin.


                I am having trouble with a DHT22 temperature sensor to work on Arduino Mini Pro