Is there a guide to writing your own library in SimpleIDE?
maxhirez
Posts: 2
I tried writing my own library for SimpleIDE and while I can get it to compile, I can't get it to function. As near as I can figure, I don't understand the cmm .a file or something. In any case, I could use a comprehensive guide to the lib structure for SimpleIDE. I'm coming to it from Arduino, xCode and Ultrix C if that gives you any hints to the mindset, and if anyone has an insight that can solve the problem instantly, here's the folder structure I have built:
-libmyLib
Incidentally, the code is to use a cheaper distance sensor than an official Ping-as a new member, I'm hesitant to be too specific about what I've created. What is the community take on that kind of topic? The sign up rules seemed to be saying you both could and couldn't talk about that sort of thing. It was unclear...
-libmyLib
- -cmm
- -libmyLib.a
- -myLib.c
- -myLib.h
- -libmyLib.h
Incidentally, the code is to use a cheaper distance sensor than an official Ping-as a new member, I'm hesitant to be too specific about what I've created. What is the community take on that kind of topic? The sign up rules seemed to be saying you both could and couldn't talk about that sort of thing. It was unclear...
Comments
The SimpleIDE Help menu will lead you to the SimpleIDE User Guide PDF. Page 30 of the guide contains the start of the "How to Create a Simple Library" section.
If you followed those instructions and still had the problem, you may need to give more details in order to get some help here.
dgately
SimpleIDE builds the folder structure for you ... if you let it. I seriously recommend SimpleIDE & Project View for library development at least in the beginning. To get started make a new project with Menu -> Project -> New and call the project "libname" in the dialog that opens (use a .c filter or a .cpp file dialog filter) I recommend starting libraries in Documents\SimpleIDE\Learn\Simple Libraries\MyLibs\"libname" Once the libname project is started, the MyLibs\libname folder will contain libname.c and libname.side. Once you compile you should get MyLibs\libname\cmm. So, there is your structure. The User Guide should help understand more details like setting the Create Project Library in the Project Manager's Linker tab.
Wish I had some water-proof pings for my car - Parallax doesn't offer one. Do you have a waterproof design? I don't know what to say about competing products. Just float a trial baloon. Parallax employees are some of the nicest people on earth - it is very rare that they dissuade any topic. We get into all kinds of discussions around here. Sometimes conversations go off in the woods ... forgive us in advance
#include "libpropeller/myclass/myclass.h"
From simple IDE all you have to do is Add Include Path to the root libpropeller folder and you're good to go. This method also works well outside of SimpleIDE in other editors or using a makefile. But please note that this uses a non-standard code organization.
Nope, not a problem. From the C++ language specs (which I quoted here) it says that inline functions only exist once. So it doesn't hurt to include them from multiple sources.
With inline headers you typically have much fewer .cpp source files. I usually have 1 main.cpp, and then one .cpp for each class with static variables (which cannot be defined in .h files because those can't have multiple definitions).
Hmmm. Thinking about it now, it might be better to make it so that the end user does the following in their main.cpp (and only in their main.cpp):
#include .h files for classes without statics
#include .cpp files for classes with statics
Everywhere else #includes the .h file.
This way, you can have a single propeller-elf-g++ command for compilation, with a single parameter (main.cpp). No need for complicated makefiles, no need for tracking which .cpp files you need to compile. Much easier. It's also a project dependent option: it doesn't change the library (so you can do it the old way if you want).
MyClass.h
main.cpp is level 0, so whatever it includes is level 1. Assuming main.cpp includes things only once, then there will be at most a single copy of the headers .cpp file. This does assume a single compilation unit, but that's what I'm going for anyway.
Reference: Predefined Preprocessor Macros:
http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
MyClass.h
You have to move the MyClass.cpp include out so that your main.cpp inclusion of MyClass.h doesn't have to be first. Otherwise, other classes (ClassThatUsesMyClass.h) will include it at a non-level 1 include level but define the variable that prevents it from being included again.
But, if we're going to be in a single compilation unit why not just include it directly:
MyClass.h
MyClass.h
First off, there are no side effects. This is opt-in. Once you do, you'll be able to compile like follows:
The compiler will then, automatically, pull in all the code needed as long as your include paths are set up correctly (or it's local). There's no problem with multiple definitions since there's only one translation unit. It works well, and in my program dropped the size down 16 bytes I think I'll add this to libpropeller (there's only one .cpp anyway...).
One side note: I'm still looking for a good .S solution (for cog code). I haven't figured out a way to auto include that from the .h files.
Can you provide a small example application that uses some libpropeller code (and build instructions with path setups, etc...) using the last solution?
I have something to try with it.
Thanks.
I can, but it will have to wait until Tuesday. I've loaned out all my Propeller boards.
We are currently working to release a tutorial series all about Simple Libraries on our Learn site, and it will include a section on creating your own Simple Libraries.
Although the series is not quite ready for publishing yet, expect to see it make its debut in the very near future.