Programming/Debugging a custom library

Hello Arduino Forum,

I have a quick question, but I'm sure it won't be too hard to answer for any experienced Arduino-Programmer.

Recently I wrote some code to display numbers on a 4 Digit Display (Digits as in 7 segment digits). It was working fine but then I tried to write it into a little library (for personal use though I could share it if anyone is interested).

I followed the library-Tutorial but must have messed up something in the code somewhere. Now, when I try to use the class (that is, the class in the library), the compilation output of the IDE only gives me the errors at the moments where I try to use my custom-object.

But where do I find the errors of the library? It's not that long, I could probably find the errors just by staring at the code. But there must be a better way, right?

Also, is there a way to code the necessary files, (.h and .cpp) in the IDE? (It doesn't let me open them) How do you do it when you write your librarys. Do you use a different IDE? Any suggestions are welcome.

Thanks already

PS: I found the mistakes. I put the code as it was back into the main Sketch to see what would happen. (It was some missing underscores and that stupid semicolon at the end of class definitions >:( ) Still, my question remains:
What do you use to program libraries and how do you debug them, where are the compile errors shown.

Every error message gives you the exact file, file line number, and character position where the error was trapped....

Regards,
Ray L.

Yes and No.

I tried a few different things and you are right. A mistake in the .cpp will show up. That missing semicolon after the class Definition however is what I really tripped over since its error is not on that line but the next (not necessarlity in the same File). In my case that was the initialisation of an object of exactly that custom class which would fail. So I thought it was because of some internal errors of the class member function definitions. And since it didn't give me any hint outside my sketch file I thought it didn't give xou those at all.

Allright. Problem solved, won't happen again. I still think it's weird that you are not really able to programm the .cpp, .h files in the Arduino-IDE, are you?

I could probably find the errors just by staring at the code. But there must be a better way, right?

Wrong! We don't run your code to find the bugs in it do we.

Mark

thimogul:
Yes and No.

I tried a few different things and you are right. A mistake in the .cpp will show up. That missing semicolon after the class Definition however is what I really tripped over since its error is not on that line but the next (not necessarlity in the same File). In my case that was the initialisation of an object of exactly that custom class which would fail. So I thought it was because of some internal errors of the class member function definitions. And since it didn't give me any hint outside my sketch file I thought it didn't give xou those at all.

Allright. Problem solved, won't happen again. I still think it's weird that you are not really able to programm the .cpp, .h files in the Arduino-IDE, are you?

It is not always possible for the compiler to pin-point the exact problem. It can only point out where it first encounters illegal syntax. But, in most cases, the source of the error will be at, or very shortly before, the position indicated in the error message. In the case of a mis-placed curly brace, the actual error can be FAR from the indicated position. But, even so, looking at the code is nearly always the best, if not the only, way to pin-point the error.

Regards,
Ray L.

I still think it's weird that you are not really able to programm the .cpp, .h files in the Arduino-IDE, are you?

Sure you are. On the far right of the IDE, there is an icon to create a new tab. Name the file in the tab to have a .h extension. Create another tab; use the same name with a .cpp extension.

Develop your library, in the IDE. Then, move the .h and .cpp files to a folder in the libraries folder to be able to reuse it.