8 years, 3 months ago.

Need to edit unused variable or rotary encoder won't work

I've noticed a strange problem with my latest program. I've decided to add a rotary encoder and created a encoder.cpp and encoder.h files. However, I'm observing some strange behavior. If I edit the encoder.cpp file, compile the program and upload it to my LPC1768, the encoder works fine. If I then compile it again, changing nothing, the encoder stops working. The silly workaround I've found was adding a line to encoder.cpp:

int asdf = 0;

I then change the 0 to a random number every time I compile the program. The integer asdf is never used in the program, so it does seem strange. It works, but it is annoying to have to keep changing a line of code that I don't actually use in my program. Resetting the LCP1768 doesn't change anything, so it is some error during compiling.

Has anyone ever experienced anything like this? Does anyone know how to solve it?

Thanks!

1 Answer

8 years, 3 months ago.

If you click on the arrow next to compile and select Compile All does it work every time even if you haven't changed anything?

What you are seeing sounds like an issue with the incremental build system, when you hit compile it checks if a .cpp file has changed, if it hasn't changed then it doesn't recompile it, it uses the previous result for that file.

Compile All does a clean build, it forces the system to recompile everything even if it doesn't think it needs to.

Normally this sort of problem is caused by poorly defined dependencies, the online system generates these automatically based on the #includes in the cpp.

Unfortunately these problems can sometimes be a nightmare to track down and it's easier to just always do a clean build and live with the slightly longer compile time.