C++ doubt: Separate file for Functions/Methods when building locally [Solved]

I have almost no experience with C++ and I’m used to the Arduino platform. On the Arduino when I had a bunch of related Functions, I’d put them in a new tab and the Functions would be automatically callable from setup() and loop() with no extra work.

So how do I create a file which contains all my functions and make this file available to my application.cpp? (I’m sure there’s some work involved in making this happen :smile: )

@nitnut,

I assume you are talking the Web IDE?

Once you made a new project and saved it, you can create a new By clicking on the ‘!’ beside the project_name.ino.

Give it another name for the .h file create and the .cpp file will have the same name as well.

Paste all your functions in the .cpp and the .ino will automatically include the files.

:slight_smile:

@kennethlimcp

I was talking about when building files Locally not using the Web IDE. The general process is that I put my code (which includes Setup(), Loop(), all other Functions) into the Application.cpp file. Then I “make” the build folder. The reason I want this is because my Application.cpp file has become large and takes me ages to scroll up and down looking for a particular function.

So I was hoping you could tell me if I have to create a new file & extension to paste all my functions into like : “customfunctions.h” or “customfunctions.cpp” or something else ?

And would I have to add a line at the top of application.cpp like : “#include customfunction.h” or “#include customfunctions.cpp” ?

I’m also looking for something that is compiler friendly that doesn’t require me to do a “make clean” all the time. Hmmm, something tells me I’m very close the answer :smiley:

I haven’t worked on the local IDE so i might not be the best to tell you the answer.

But based on what i did last time on microcontrollers,

I create a new XXXXXX.h file and place it in the same directory as application.cpp

Then at the top of the application.cpp file i add in #include "XXXXX.h"

1 Like

@kennethlimcp I’ll give it a go and let you know in an hour or two. Thanks :smile:

@kennethlimcp Works! Thank you! :smiley:

2 Likes

Have fun!

It’s been a while since i used a Local IDE cos the :spark: IDE is really fun and my projects aren’t growing too big for it to handle as of now :smiley: