I am getting back into programming, specifically the Arduino platform.
I used to be into Visual BASIC, then started using Code::Blocks when I switched to Ubuntu to tinker around.
That being said, I want to learn how to create simple libraries, with the eventual goal of being able to grab the data sheet from a chip, and create a library for that chip.
I peruse the forums on Arduino.cc and the forums here, but they seem somewhat specifically oriented to a given library problem; all I want is to better understand the basic nuts and bolts, so that I can start writing my own.
As far as I remember, the .h file is the header file that contains the commands and functions that the Arduino IDE uses to compile a sketch with, and the .cpp file dictates how the stuff in the .h file works.
Do I remember that correctly enough?
I know this is a big bite to chew, so that is why I am taking baby steps until I am ready to start writing libraries for chipsets.
One of the final steps I need to figure out before I feel I am ready, is how to associate what is between the .h and .cpp files and how to relate them to what the data sheet says the chipset can do, ie the section of the datasheet that shows what commands are used to operate the chip.
you don't have a main function in library code. The rest is more or less the same as always.
When you compile it, you tell it its a library, not an executable, which is specific to your IDE or compiler etc. In windows youll generate a .lib and .dll files in a pair; the executable that uses the library uses the dll, and programs that are built to use them consume the lib file. Or you can just make the lib, and link it without the dll. The dll is there so you can hot-swap a new version in without recompile and redistribute the executable, is all. Unix does more or less the same thing with shared objects.
You need the .h file for the library as well as the .lib, yes. A .lib written in another language works fine, as long as the .h file maps the functions to a compatible C style format.
This is how you do it normally but embedded systems often have weirdness. Youll need an ard expert to help you with the platform if it is not simple and similar to the above. There are gotchas ... one library I worked with a lot was in fortran, and I had to transpose every matrix or vector and count from 1, not zero, when talking to it (not sure if that was the language or the programmer, on the index thing, I don't know much fortran).
not sure what you are asking. But the header file to a library are used by the calling program (library user) to map whatever is in the library into something that C or C++ can work with. So if whatever the library does uses an array of 32 bit integers, for example, the c++ header defines it as int whatever[size] even if the original code was fortran or java or whatnot.
The library proper is machine code. The header file maps the functions in the library to a callable name in C++, and when you compile the library user, the linker and compiler and such put it all together.
The code for the library itself are used to make the library into its machine code usable form. The header file MIGHT be in c++ and it MIGHT be usable by the consumer. Often, it is. But that is just a friendly coincidence that you can exploit when it goes your way, and you can do this intentionally when writing your own. You can't rely on this connection. But you can expect that most libraries that you would use do have a .h file bundled with them for the consumer program to use.
You should make sure you understand
-- Difference between declarations and definitions,
-- linkage and storage duration
In general, definitions go into the source files that are linked into the library; declarations of library symbols with external linkage go into the header file(s).
Arduino has a few caveats since it obscures the entire build process: the back-end process is the same, like @jonnin describes, but it makes things slightly harder to understand.
IIRC, In the context of Arduino, libraries are distributed solely as source code. This is because compiled code is not (in general) a portable thing between processors (for the same reason that binaries can't usually be moved cross-architecture).
There are no dynamic libraries (.so/.dll files) in the context of Arduino: there's no filesystem, and no dynamic linker. Everything is statically-linked. https://www.arduino.cc/en/Hacking/libraryTutorial
You can turn on the "verbose" mode in the settings panel and take a look at how the Arduino core library is built and then linked. (This is also a good starting point for doing external builds, if you can't stand the interface.)