Go Down

Topic: File Structure, How to work with it (Read 740 times) previous topic - next topic

XaTrIxX

Hi!

I tried the basics and I fail. I simply want to include a .h and a .c file in the same folder as my main program sits.

I have

Main.ino -> contains setup() and loop()
MyLib.h
MyLib.c

All in the same folder.

Main.ino has
#include "MyLib.h"

MyLib.h has
#include "Arduino.h"

and MyLib.c has
#include "Arduino.h"
#include "MyLib.h"

When compiling it says: MyLib.h No such file or directory. Where is it searching? I didn't use #include <MyLib.h>

pYro_65

#1
Jan 22, 2013, 04:13 pm Last Edit: Jan 22, 2013, 04:15 pm by pYro_65 Reason: 1
Use the open button to re-open your sketch so the tabs appear identifying the .h & .c, also gcc is a c++ compiler. You can stick with .cpp files.

Restarting the IDE is necessary when adding new libraries to the libraries folder.
Forum Mod anyone?
https://arduino.land/Moduino/

PaulS

Quote
MyLib.c

Unless you really know what you are doing, this is not a good idea.

Is your sketch really called Main.ino? Calling a sketch Main is really not a good idea.

When you open the sketch, do all the files open in separate tabs?

Specific error messages are a good idea, not what you remember of them.
The art of getting good answers lies in asking good questions.

XaTrIxX

Oh, I even had to restart the application. Funny.

Well, if its g++ I can also use C files :) Thanks for answering.

PaulS

Quote
Well, if its g++ I can also use C files

You can, but g++ does name mangling on C++ files, but not on C files. The C++ code, including the sketch, won't be able to call the C functions, unless you use the proper directives in the header file.
The art of getting good answers lies in asking good questions.

MarkT

If its really a library, why not put it in its own directory under libraries...  That's way it can be shared.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

pYro_65


If its really a library, why not put it in its own directory under libraries...  That's way it can be shared.


Once its built the libraries folder is suitable, not while its in development; example files, additional library files all require a restart to be usable in the IDE, a simple sketch just needs re-opening. This may not seem like much, but can get very frustrating when actively modifying numerous files.
Forum Mod anyone?
https://arduino.land/Moduino/

Go Up