myClass.h: No such file or directory

Hi everyone,

I am trying to create a simple librairy.

For Calculette one; I have the following errors:

myClass.h: No such file or directory

if I use #include "myClass.h" in the myClass folder:
myClass:6:1: error: 'Calculette' does not name a type

Why does IDE 1.8.10 does not accept the files sructure?

I tried to put the H and CPP files in a src folder (myClass/src , myClass/myClass/myClass.ino) without success.

I joined a zip file , in case and a phootograph of the folders structure.

I visited the Morse example, the Oreilly.Arduino.Cookbook.2nd.Edition.Dec.2011.pdf example: dumb I am stuck.

Regards,

JPDaviau


INO file

#include <myClass.h>

Calculette one;

void setup() {

  one.calculette(2, 4);
  one.exposant();  // from constructed  class _variables
  one.exposant(2, 4);
}

void loop() {
  // put your main code here, to run repeatedly:

}

H file

#ifdef _c
#error This source file is not C  but rather C++.
#endif

/*  */
#ifndef myClass_H
#define myClass_H
 // extern myClass calculette;
#endif

#if ARDUINO >= 100 
#include "Arduino.h"  // for 1.0 and later 
#else 
#include "WProgram.h" // for earlier releases #endif

#include <iostream>
#include <cmath>

class Calculette
{
private:
int _base;
int _pow;

public :
  calculette (uint_8_t number, uint_8_t exposant); ////construct
  ~calculette(); //destruct

 Calculette::calculette (uint_8_t number, uint_8_t exposant);
  void Calculette::exposant();
  int Calculette::exposant(uint_8_t number, uint_8_t exposant);
};


//extern myClass2 fonctionner;
#endif

CLASS file

#ifdef _c
#error This source file is not C  but rather C++.
#endif

#include <myClass>


using std::cout;    // le programme utilise cout.
using std::cin;     // le programme utilise cin.
using std::endl;    // le programme utilise endl.

class Calculette
{
private:
int _base;
int _pow;

public :
 calculette (uint_8_t number, uint_8_t exposant);////construct
 ~calculette(); //destruct
 void exposant();
 int exposant(uint_8_t number, uint_8_t exposant);


Calculette::calculette (uint_8_t number, uint_8_t exposant) 
  {
    _pow = number;
    _base = exposant;
  }

 

  Calculette::~calculette(){}

  void Calculette::exposant()
  {
  unsigned int out;
    for (int x = 2, int y = 2; y < 9; y += 2)
      {
      out = pow(_base, _pow);
      }

    if (out > 60000)
      {
      return out;
      }
    else
      {
      printf("Number is  over 60000.");
      }

  }


  int Calculette::exposant(uint_8_t number, uint_8_t exposant)
  {
 unsigned int out;

    for (int x = 2, int y = 2; y < 9; y += 2)
      {
      out = pow(number, exposant);
      }

    if (out > 60000)
      {
      return out;
      }
    else
      {
      printf("Number is  over 60000.");
      }

  }

};

myClass.zip (3.28 KB)

You can place your library in the same folder as all the other libraries you install from the IDE.

Go to File -> Preferences ->Settings -> Sketchbook location

the IDE will/has create a libraries subfolder there. You can add your library there. Have a look at the libraries already in there for the folder structure usually used.

Hint: If you write your software including variable names and comments in English, it will make it easier for everyone else to read your code. I am a non native English speaker as well and I stopped using my language for programming a long time ago.

Jean24816:
I tried to put the H and CPP files in a src folder (myClass/src , myClass/myClass/myClass.ino) without success.

When the source files are under the src subfolder of the library folder, that is called the 1.5 Arduino library format. In order for libraries of that format to be recognized by the Arduino IDE, you need to have a library.properties file in the root of the library folder (libraries/myClass/library.properties). Information on the library.properties file is in the Arduino library specification:

I started by putting myClass.h and myClass.cpp in tabs.
Changed

#include <MyClass.h>

to

#include "myClass.h"

in two places.
Fixed 'uint_8_t' to 'uint8_t' in a bunch of places.

Fixed 'calculette' to 'Calculette' in several places.
Fixed "for (int x=2, int y=2;" to "for (int y=2;" since 'x' is not used.
void Calculette::exposant() tries to return a value.

Unfortunately it was not clear what you wanted your class to do. Your sketch produces no output. After fixing a LARGE quantity of syntax errors I was able to get it to at least compile:
Sketch:

#include "myClass.h"

Calculette one(2, 4);

void setup()
{
  one.exposant();  // from constructed  class _variables
  one.exposant(2, 4);
}

void loop()
{
  // put your main code here, to run repeatedly:
}

myClass.h:

/*  */
#ifndef myClass_H
#define myClass_H

#if ARDUINO >= 100
#include "Arduino.h"  // for 1.0 and later
#else
#include "WProgram.h" // for earlier releases #endif
#endif

//#include <iostream>
//#include <cmath>

class Calculette
{
  private:
    int _base;
    int _pow;

  public :
    Calculette (uint8_t number, uint8_t exposant);     ////construct
    ~Calculette();  //destruct

    void exposant();
    int exposant(uint8_t number, uint8_t exposant);
};

#endif

myClass.cpp

#include "myClass.h"

Calculette::Calculette (uint8_t number, uint8_t exposant)
{
  _pow = number;
  _base = exposant;
}

Calculette::~Calculette() {}

void Calculette::exposant()
{
  unsigned int out;

  for (int y = 2; y < 9; y += 2)
  {
    out = pow(_base, _pow);
  }

  if (out > 60000)
  {
    // return out;  // Can't return a value from a function that returns 'void'.
  }
  else
  {
    printf("Number is  over 60000.");
  }

}


int Calculette::exposant(uint8_t number, uint8_t exposant)
{
  unsigned int out;

  for (int y = 2; y < 9; y += 2)
  {
    out = pow(number, exposant);
  }

  if (out > 60000)
  {
    return out;
  }
  else
  {
    printf("Number is  over 60000.");
  }
  return 0;
}

Thank you so much.

I will work at your suggestions.

Although I made all the corrections, the compiler pretend :

#include

^~~~~~~~~

where can I flush that memory?

I added a library.properties file

name=myClass
includes=myClass.h
architectures=avr
author= Jean Pierre Daviau
category=test
depends=ArduinoHttpClient
maintainer=
paragraph=
sentence=A learning how to do a library
url=http://
version=1

AND a library.json file

{
"name": "myClass",
"description": "compute",
"keywords": "number exposant compute one",
"authors":[
    {
 "name": "Moi",
 "email": "",
 "url": "",
 "maintainer": true
    }
 ],
"repository":
    {
 "type": "git",
 "url":  "",
    },
"version": "1",
"homepage": "",
"frameworks": "Arduino",
"examples":[
 "examples/*/*.ino"]
"examples":[
 "examples/src/*.h"]
"examples":[
 "examples/src/*.cpp"]
}
#include <myClass.h>

compute one(2, 4);

void setup() {

  one.compute(2, 4);
  one.exponent();  // from constructed  class _variables
  one.exponent(2, 5);
}

void loop() {
  // put your main code here, to run repeatedly:

}

JPD

myClass.zip (3.33 KB)

You've omitted important information from the error message.

When you encounter an error you'll see a button on the right side of the orange bar in the Arduino IDE "Copy error messages" (or the icon that looks like two pieces of paper in the Arduino Web Editor). Click that button. Paste the error in a reply here using code tags.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

Jean24816:
I added a library.properties file

Unrelated to the error, but yust FYI, the library.properties file is only required by the Arduino IDE when your library is in the 1.5 format. At least in the myClass.zip attachment you provided, the library is in the 1.0 format, which does not require a library.properties file to be present for the Arduino IDE to recognize the library. That said, a library.properties file is required in order to import even 1.0 format libraries to the Arduino Web Editor (at least the last time I checked), and it is also required for all libraries (1.0 and 1.5 format) added to the Library Manager, so it's not a bad idea to add the file to any library.

Jean24816:

category=test

Please use one of the categories listed in the Arduino library specification. Use of a category value not in the specification results in the Arduino IDE displaying an annoying warning on every compilation:

WARNING: Category 'test' in library myClass is not valid. Setting to 'Uncategorized'

Jean24816:
AND a library.json file

That file is only used by PlatformIO and has no effect on the Arduino IDE.

Hi,

I clipped the new zip file with the src directory and all the changes in the first post. I am sorry for the change in the folder structure

myClass

├── examples
│ └── myClass
│ └── myClass.ino
├── keywords.txt
├── library.json
├── library.properties
├── src
│ ├── myClass.cpp
│ └── myClass.h

Arduino: 1.8.10 (Windows 10), Board: "Node32s, Default, 80MHz, 921600, None"

myClass:2:21: error: myClass.h: No such file or directory

compilation terminated.

exit status 1
myClass.h: No such file or directory

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Make sure you have the following folder structure:

{sketchbook folder}
└── libraries
└── myClass
├── examples
│ └── myClass
│ └── myClass.ino
├── keywords.txt
├── library.json
├── library.properties
└── src
├── myClass.cpp
└── myClass.h

As Klaus_K mentioned earlier, you can find the location of {sketchbook folder} at File > Preferences > Sketchbook Location.

Did you remember to run "Tools->Manage libraries..." to get the IDE to scan for new libraries? Until you do that or re-start the IDE your new library won't be seen.

johnwasser:
Did you remember to run "Tools->Manage libraries..." to get the IDE to scan for new libraries? Until you do that or re-start the IDE your new library won't be seen.

With Arduino IDE 1.6.6 and newer, the libraries folders are scanned on every compilation. Since the error output shows that @Jean24816 is running Arduino IDE 1.8.10, not having restarted or run manage Libraries... is definitely not the cause of the "No such file or directory" error.

It is true that, even with the modern IDE versions, you still need to do that before the manually installed library's examples will show under the File > Examples menu or the library will be listed under the Sketch > Include Library menu, but that's not the issue in this particular case.

Hi again,

And pardon me for my numerous mistakes.

My god it was horrible.

I get it , it works and I have uploaded a last zip file with the src directory and all the changes in my first post.

It seems I cant do that in this one.

Regards,

JPDaviau

I'm glad to hear it's working now!

Would you mind telling us what the problem ended up being? That would be useful to others who have a similar problem and find this topic while searching for a solution.

I clipped the solution in a zip file. The main thing was.

1- That I finally imported my library with sketch import zip file

2- Compute one(2, 4); //construct a class of type Compute

There is still a strange problem with the output of the 3 functions using prntout = pow(this->_base, this->_pow); and prntout = pow(number, exponent);

2,4

prntout 15

prntout = 16

JPDaviau

Jean24816:
There is still a strange problem with the output of the 3 functions using prntout = pow(this->_base, this->_pow); and prntout = pow(number, exponent);

2,4

prntout 15
prntout = 16



JPDaviau

I suspect that the problem is that 'pow()' takes arguments of type 'double' and returns a value of type 'double'. You are passing arguments of type 'uint8_t' and saving the result in an 'int'. In one case the value returned by 'pow()' may be 15.99999 which gets truncated to 15. I don't know why the results are different for the two cases. My guess would be that in one case the math is done at run time by the Arduino library and in the other case the math is done at compile time by the compiler which probably uses a more precise representation of 'double'.

johnwasser:
I suspect that the problem is that 'pow()' takes arguments of type 'double' and returns a value of type 'double'. You are passing arguments of type 'uint8_t' and saving the result in an 'int'. In one case the value returned by 'pow()' may be 15.99999 which gets truncated to 15. I don't know why the results are different for the two cases. My guess would be that in one case the math is done at run time by the Arduino library and in the other case the math is done at compile time by the compiler which probably uses a more precise representation of 'double'.

Exact. I changed for double and the numbers are ok

2.00,4.00
prntout 16.00
prn2.00,4.00
prntout 16.00
prntout = 16.00