No .cpp or .h files in arduino-timer library

I have experience with a few libraries and assumed that there must be a .cpp and .h fils included in the library along with examples and other stuff.

I tried to compile and sketch errored on the #include <arduino-timer.h>.

The library was listed in IDE library manager folder (installed), and I can see it in the Audrino/Libraries shown below.

Please advise
Jim

What files are in the src folder of the library ?

I have
image

Exactly which sketch were you trying to compile ?

I used the timer_full sketch which is one of the examples from the arduino-timer lib
It faulted on the bolded statement below:

/*
 * timer_full
 *
 * Full example using the arduino-timer library.
 *  - Setting a different number of tasks with microsecond resolution
 *  - disabling a repeated function
 *  - running a function after a delay
 *  - cancelling a task
 *
 */
#include <arduino-timer.h>
****auto timer = timer_create_default()**;** // create a timer with default settings
Timer<> default_timer; // save as above

__________________________________________________________--

The Output window showed the following

Alternatives for arduino-timer.h: []
ResolveLibrary(arduino-timer.h)
-> candidates: []
C:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino\Anemometer\timer_full\Using%20Clock%20only%20Failed_copy_20220411120655\Using%20Clock%20only%20Failed_copy_20220411120655.ino:14:10: fatal error: arduino-timer.h: No such file or directory
compilation terminated.

Compilation error: exit status 1


I also have your header files, and I thought that I need the arduino-timer.cpp file that contains the code like my other libraries.

Please explain
Thanks

Whilst there is a convention that both .h and .cpp files must be used in a C++ library they do not have to be. It is sufficient for there to be just a .h file and for all of the library code to be in it, not just declarations of variables and functions

Thanks

I checked and made sure that arduino-timer is compatible with UNO and it is.

The complier stopped at:
timer_create_default(), // create a timer with the default settings

I searched the .h file and found:
inline Timer<>
timer_create_default()
{
return Timer<>();

I cant find "inline" but it looks like this is the function invoked by the .ini sketch.

I am really stuck. I don't understand why the compiler fails on an example listed within it the example list within its own library.

Any suggestions?

Jim

First of all, let's remove as much irrelevant complexity from the system as possible.

You are getting distracted by looking at this code, but it is almost certain that it is irrelevant to the problem. If you examine the error message:

It clearly points to the problem being with this line of the sketch:

This can be checked via a simple experiment.

Change the sketch code to this:

#include <arduino-timer.h>
void setup() {}
void loop() {}

Now try compiling the sketch again. Does the error still occur?

Using board 'uno' from platform in folder: C:\Users\jgmor\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5
Using core 'arduino' from platform in folder: C:\Users\jgmor\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5
Detecting libraries used...
"C:\\Users\\jgmor\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\jgmor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\jgmor\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\standard" "C:\\Users\\jgmor\\AppData\\Local\\Temp\\arduino-sketch-9823A3348E53AA13FABDFF2DF01EF4D5\\sketch\\arduino-timer test.ino.cpp" -o nul
Alternatives for arduino-timer.h: []
ResolveLibrary(arduino-timer.h)
C:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino\Anemometer\arduino-timer test\arduino-timer test.ino:1:10: fatal error: arduino-timer.h: No such file or directory
 void setup() {
          ^~~~~            
compilation terminated.
  -> candidates: []

Compilation error: exit status 1

I think so, in that we are distilling the problem down to something more simple and thus easier to troubleshoot.

This proves that none of the code from the more complex sketch is related to the error. So we don't need to think about any of that. We know for certain that here is nothing wrong with the bare minimum part of the sketch code:

void setup() {}
void loop() {}

Please do this:

  1. Select File > Preferences from the Arduino IDE menus.
  2. Select and copy the contents of the "Sketchbook location" field
  3. Press Ctrl+A to select all the text.
  4. Press Ctrl+C.
    This will copy the selected text to the clipboard.
  5. Use Ctrl+V to paste the copied output to a reply here.

c:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino\Anemometer

OK, I see the problem now.

Libraries must be saved to the libraries subfolder of the path specified by the "Sketchbook location" preference.

So in your case the "arduino-timer" library would need to be installed here in order for the Arduino build system to find it while compiling your sketch:

c:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino\Anemometer\libraries\arduino-timer

But from the screenshot you shared, I can see that the library is in a different location:

c:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino\libraries\arduino-timer

So if you want to keep your current "Sketchbook location" setting, you should reinstall the library. I'll provide you with instructions for doing that:

  1. Select File > Quit from the Arduino IDE menus if it is running.
  2. Start the Arduino IDE.
    This restart is needed due to a bug in the beta phase Arduino IDE 2.x (which I can tell you are using from the output): arduino/arduino-ide#796
  3. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view.
  4. Click on the "Filter your search..." field.
  5. Enter the following text: arduino-timer
  6. You should see "arduino-timer by Michael Contreras" in the "Library Manager" search results. Click on it.
  7. Click the INSTALL button.
  8. Wait until you see the notification:

    Successfully installed library arduino-timer:2.3.1

Now try compiling your sketch again.

You will also need to reinstall any other libraries you installed before changing your "Sketchbook location" preference (and even any you installed during the session after changing the preference due to arduino/arduino-ide#796).

Still trying to get my head around the file Arduino file schema.

Please confirm my understanding below:

  1. Set the sketchbook location to the folder that contains the library folder:
    c:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino
    This folder contains the library folder.

I then saved as a sketch that compiled/uploaded/ran, to the folder, Anemometer
Jim 5, that was under the previous Aucrino folder. This sketch required no #include command.

This sketch failed to recognize the commands/function that are non-C++, arduino functions/commands as shown below:


Serial.begin(9600);// Open serial communications
^~~~~~
pinMode(AnmCnt,INPUT); // Set Anemometer contact to AnmCnt
^~~~~
pinMode(AnmCnt,INPUT); // Set Anemometer contact to AnmCnt
^~~~~~~
delay
Serial.println(AnmPls)


I think these commands need the Arduino library access because they are not standard C++ functions. This is conjecture only. Is this right?

2 in order to use the folders to organize sketches in arduino/anenometer and arduino/raingauge, I need to first create these folders (file explorer), close the ide, then move the folder under arduino to these folders.

Is this correct?

Thanks for your help.

Wrong. It should be "Set the sketchbook location to the folder that contains the libraries folder".

The libraries folder is where your libraries are stored. Each library is in a separate folder under the libraries folder.

For example:

<sketchbook location>/
└── libraries/
    └── arduino-timer/
        ├── CONTRIBUTING.md
        ├── LICENSE
        ├── Makefile
        ├── README.md
        ├── examples/
        ├── extras/
        ├── keywords.txt
        ├── library.properties
        └── src/

I don't have enough information to be able to determine the cause. Please put the entire "Anemometer Jim 5" (or whatever it is) folder in a ZIP file and attach it in a reply here.

It is not really clear to me what you are asking, but you certainly are not required to use Windows File Explorer. You can create folders and save sketches anywhere you like via "File > Save as..." in the Arduino IDE. In fact, I would recommend you to use that rather than messing with the sketch folders directly because it will make it more likely that the sketch is saved in the correct format (the sketch is a folder, not a file, and the folder must contain a .ino file matching the folder name).

Thank you very much for your patience.

Where did you get the symbols:
└──
└──
├──

They are very helpful in describing the file structure necessary for Arduino. They would be very useful to me since I am struggling with communicating my proposed file structure in my narritive.

Thanks
Jim

You are welcome.

Effectively describing file system structures in text is the sort of subject I find very interesting. I spent some time considering various approaches and have settled on the format you see in my previous reply.

This is the output from the tree tool:

Installation

Windows

There is a native Windows version (tree.com) but I don't like the way it lists files as much as the Linux version. Fortunately, you can get that version for Windows as well. I sourced it here:

Linux

You should be able to get it from any package manager. I use "APT" after finding that the security sandboxing imposed by "SnapCraft" on that package interfered with my ability to use tree as I needed.

apt install tree

macOS

I haven't tried it, but I see there is a "Homebrew" formulae, which would likely be the preferred installation approach if it is not pre-installed:

brew install tree

Usage

I use it like this:

tree -AF <path>/

-A flag

The reason I use the -A flag is to ensure the nicer folder structure indicator characters. Without it, the output looks like this:

> tree foo

foo
|-- bar
|   `-- bar-file.txt
|-- baz
|   |-- baz-file.txt
|   `-- baz-sub
|       `-- baz-sub-file.txt
`-- foo-file.txt

Unfortunately, you might find that the command shell ("cmd" or "PowerShell") can not properly output the ANSI lines produced by -A. I recommend using "Git Bash", which is part of the "Git For Windows" installation:

-F flag

The reason I use the -F flag is to differentiate empty folders from files:

$ tree -A foo

foo
├── bar
│   └── bar-file.txt
├── empty
└── foo-file.txt

:confused: is empty a folder or a file?

$ tree -A -F foo

foo
├── bar/
│   └── bar-file.txt
├── empty/
└── foo-file.txt

:slightly_smiling_face: all is clear!

Trailing /

The reason I use the trailing / on the path argument is for consistency with the trailing / added to the subfolders by the -F flag:

$ tree -A -F foo/

foo/
├── bar/
│   └── bar-file.txt
├── empty/
└── foo-file.txt

Using your recommendation and explanation of the "TREE" command. I took relevant sections from my directory that include 6 more projects that are not shown.

c:\Users\jgmor\OneDrive\Documents\Microcontroller Hardware and Software\Arduino>TREE
├───libraries
│   ├───Adafruit_AHT10
│   │   ├───assets
│   │   └───examples
│   │       ├───adafruit_aht10_test
│   │       └───adafruit_aht10_unifiedsensors
│   ├───Adafruit_BusIO
│   │   └───examples
│   │       ├───i2corspi_register
│   │       ├───i2c_address_detect
│   │       ├───i2c_readwrite
│   │       ├───i2c_registers
│   │       ├───spi_modetest
│   │       ├───spi_readwrite
│   │       ├───spi_registers
│   │       └───spi_register_bits
│   ├───Adafruit_Unified_Sensor
│   │   └───examples
│   │       └───sensortest
│   ├───ADSWeather-0.1.1
│   │   ├───examples
│   │   ├───Extras
│   │   └───src
│   ├───arduino-timer
│   │   ├───examples
│   │   │   ├───blink
│   │   │   ├───blink_micros
│   │   │   ├───blink_print
│   │   │   └───full

└───Weather Station
    ├───Aduino Timer Tests
    │   └───1 min task scheduler
    ├───Anemometer
    │   ├───Anemometer Jim 1
    │   │   └───Anemometer Jim 1
    │   ├───Anemometer Jim 2
    │   ├───anemometer_rev1
    │   ├───anemometer_rev1_Hans
    │   ├───Anenometer Jim 3
    │   └───arduino-timer test
    └───Raingauge
        └───Raingauge Jim 3


I organized the entire project: Weather Station
into its component sketches: Anemometer, Raingauge, and Audrino Timer test (working on currenntly).

Everything compiles, everything uploads, and I learned some commands for the command line window that allowed me to make these drawings.

Thank you very much for your help.
Jim Moroz

Very nice! I'm glad everything is working for you.