Pages: [1]   Go Down
Author Topic: File Structure, How to work with it  (Read 380 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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>
Logged

North Queensland, Australia
Online Online
Edison Member
*
Karma: 74
Posts: 2224
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 22, 2013, 10:15:01 am by pYro_65 » Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Online Online
Shannon Member
****
Karma: 215
Posts: 12503
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

North Queensland, Australia
Online Online
Edison Member
*
Karma: 74
Posts: 2224
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: [1]   Go Up
Jump to: