Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on compilation for <cstdint> #1

Open
nimasaj opened this issue Jul 11, 2019 · 11 comments
Open

Error on compilation for <cstdint> #1

nimasaj opened this issue Jul 11, 2019 · 11 comments
Assignees
Labels
question Further information is requested

Comments

@nimasaj
Copy link

nimasaj commented Jul 11, 2019

Thanks for sharing your library. However, I get error on compiling it for Arduino pro mini (328P-3,3V) with following errors:

In file included from C:\Users\XXX\AppData\Local\Temp\arduino_modified_sketch_299657\hs300x-simple.ino:16:0:

C:\Users\XXX\Documents\Arduino\libraries\MCCI-Catena-HS300x\src/Catena-HS300x.h:20:21: fatal error: cstdint.h: No such file or directory

compilation terminated.

It points to line 20, #include <cstdint>, in Catena-HS300x.h file. Could you please share missing library/files?

@terrillmoore terrillmoore self-assigned this Jul 11, 2019
@terrillmoore terrillmoore added the question Further information is requested label Jul 11, 2019
@terrillmoore
Copy link
Member

<cstdint> is a standard c++ include file: See https://en.cppreference.com/w/cpp/header/cstdint. I don't know why your compiler doesn't include it, but it is so standard that I suspect an installation problem on your compiler.

Best regards,
--Terry

@nimasaj
Copy link
Author

nimasaj commented Jul 11, 2019

Dear @terrillmoore , I am using Arduino IDE 1.8.9 to compile the example code. Have you tested it before on Arduino?

@terrillmoore
Copy link
Member

That's exactly what I use. I have not tested with 8-bit Arduino, but I test all the time with ARM.

This is a defect in the Arduino library; they're not likely to fix it. The workaround is to detect AVR, then #include <stdint.h> and name things. So for example:

#ifdef AVR // or whatever -- check the compiler docs, I don't know the standard way to check this offhand
# define NO_CSTDINT 1  // AVR arduino has no <cstdint>; but we're coding to portable C++. So substitute.
#endif

// unless we know otherwise, use the compiler's <cstdint>
#ifndef NO_CSTDINT
# include <cstdint>
#else
// no <cstdint> -- make sure std:: contains the things we need.
# include <stdint.h>

namespace std {
  using ::int8_t;             
  using ::uint8_t;            
                     
  using ::int16_t;            
  using ::uint16_t;           
                     
  using ::int32_t;            
  using ::uint32_t;           
}

#endif

(This is what boost does, https://github.com/vancegroup/arduino-boost/blob/master/boost/cstdint.hpp)

Since I don't use AVR, I've got no way to test, though I could of course compile. But compilation doesn't really count. Feel free to submit a working pull request.

@nimasaj
Copy link
Author

nimasaj commented Jul 11, 2019

I could of course compile. But compilation doesn't really count.

I applied proposed changes to Catena-HS300x.h, and still I couldn't compile the code. Following errors were generated.

In file included from C:\Users\XXX\AppData\Local\Temp\arduino_modified_sketch_775748\hs300x-simple.ino:16:0:
 
C:\Users\XXX\Documents\Arduino\libraries\MCCI-Catena-HS300x\src/Catena-HS300x.h: In static member function 'static constexpr uint16_t McciCatenaHs300x::cHS300x::celsiusToRawT(float)':
 
C:\Users\XXX\Documents\Arduino\libraries\MCCI-Catena-HS300x\src/Catena-HS300x.h:152:9: error: body of constexpr function 'static constexpr uint16_t McciCatenaHs300x::cHS300x::celsiusToRawT(float)' not a return-statement
 
          }
 
          ^
 
C:\Users\XXX\Documents\Arduino\libraries\MCCI-Catena-HS300x\src/Catena-HS300x.h: In static member function 'static constexpr uint16_t McciCatenaHs300x::cHS300x::percentRHtoRaw(float)':
 
C:\Users\XXX\Documents\Arduino\libraries\MCCI-Catena-HS300x\src/Catena-HS300x.h:163:9: error: body of constexpr function 'static constexpr uint16_t McciCatenaHs300x::cHS300x::percentRHtoRaw(float)' not a return-statement
 
          }
 
          ^

Then, I changed the board to MKRFox1200 which is running on Atmel SAMD21 (based on ARM 32bit architecture). Still, I couldn't compile the code due to the same errors as above.

Reverting changes on Catena-HS300x.h file, didn't help too. Still, same errors, showing functions celsiusToRawT(float t) and percentRHtoRaw(float rh) are not return-statements.

@terrillmoore
Copy link
Member

Sorry you're having problems. It works for me. Sounds like the compilers in your packages don't support more recent C++. It works for me with STM32 and the compilers I have. I don't have a lot of time to look at this; if you're feeling brave, try changing the if's to equivalent return (test) ? v1 : v2:

    static constexpr float celsiusBias(float t) { return t + 40.0f; }

    // convert Celsius temperature to raw format.
    static constexpr std::uint16_t celsiusToRawT(float t)
        {
       return (celsiusBias(t) < 0.0f ? 0 : 
               celsiusBias(t) > 165.0f ? 0xFFFCu :
               (std::uint16_t) ((t / 165.0f) * float(0xFFFC));
        }

    // convert RH as percentage to raw format.
    static constexpr std::uint16_t percentRHtoRaw(float rh)
        {
        return (rh > 100.0) ? 0xFFFCu :
               (rh < 0.0) ? 0 :
               (std::uint16_t) (float(0xFFFC) * (rh / 100.0));
        }

@terrillmoore
Copy link
Member

@nimasaj branch https://github.com/mcci-catena/MCCI-Catena-HS300x/tree/issue1 compiles correctly for AVR. I have no way of knowing if it works, but if it works for you, I'll merge onto head. There was one additional problem; in AVR, <Arduino.h> is not included by default, but apparently it is on the ARM builds. The fixes will also support older compilers, and there's an easy way to add new platforms that don't support <cstdint>.

@nimasaj
Copy link
Author

nimasaj commented Aug 2, 2019

@terrillmoore Thanks for fixing compilation issues. Unfortunately, the driver is not working on Arduino pro mini.

"gHs300x.begin() failed"

@k2biru
Copy link

k2biru commented Dec 13, 2019

@nimasaj i make a simple HS300x library here k2biru/HS300xlib using arduino Wire Library.

@nimasaj
Copy link
Author

nimasaj commented Dec 16, 2019

@k2biru It's working fine with small modifications. There were typos on type uint8_t that I proposed in your repository.

@Shiny380
Copy link

Shiny380 commented Dec 29, 2020

can confirm the issue 1 branch is working correctly for arduino UNO and arduino Pro Mini (ATmega328p).
master branch does not

@terrillmoore
Copy link
Member

Hi @Shiny380, I have not tested. I do have a substitute for <cstdint> that I use in other projects, but I have not ported it back here, primarily because I can't test. If there's interest, I'll help to make this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants