-
Notifications
You must be signed in to change notification settings - Fork 638
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
Linking error (static members) in AnalogSensor.h #2624
Comments
Probably add also |
No, surely SENSOR_ERROR_OVERFLOW occurs because readAnalog is returning 65535 instead of 1023. In the debug terminal:
I don't know if it's another bug or my error in the configuration; It seems that my Lolin is starting with the ADC in "Measure the power supply voltage of VDD3P3 (Pin3 and Pin4" mode, although I am not totally sure. In any case, the latter is independent of the linking error. |
re. re. ADC, I would guess it is due to this not being picked up in the config code/espurna/config/sensors.h espurna/code/espurna/config/sensors.h Line 1529 in dc9ba63
|
So, what would be the best solution?
Yes, that was it! Thanks! |
Btw, I had similar linking problems trying to create a Singleton (AnalogMux: #2620 (comment) ). The static method (Inst()) to access the single shared instance of AnalogMux must be defined outside of the class (coming from Java I couldn't understand this restriction, but it seems to be necessary in C++), otherwise linking errors are generated. |
^ 0976bdb (assuming CI passes and I don't have to revert it for some reason)
The basic rule here is order of initialization, since static is still effectively in a global scope. Compiler is pretty bad at explaining as to why it wants this symbol present, and does not do it automatically in the global scope. Order matters in the .cpp -> .o, order of class members, so the order of static members / global static variables, so is the place where ref. |
Device
Lolin
Version
1.18
Bug description
Hello. I wrote a subclass of NTCSensor and when compiling the linker it throws an error:
This doesn't happen if you build a project that uses NTCSensor, but it does if you use a subclass of it (I have no idea why). The solution I found was to add these two lines to the end of AnalogSensor.h
Best regards
Steps to reproduce
No response
Build tools used
No response
Any relevant log output (when available)
No response
Decoded stack trace (when available)
No response
The text was updated successfully, but these errors were encountered: