Multiple source files?

Hi All...

Sorry for the really noob question. I have an application I intend to target the Arduino with, but I developed it using Open Watcom (in C++) so I could use the debugger and nicer environment. Today I began to port it to Arduino and I am running into the simplest issues.

I used the sketch->add file menu item to add a CPP file to the sketch. When I try to compile it it can not find the HPP that is included. I put the hpp in the same folder as the cpp, and I even tried to use the same add file option. No joy. Where does an hpp file go?

Thanks...

Jim

Do I have to build a library? There must be an easier way.

Building a "library" is simply a matter of providing a header file with the class definition, and a source file that implements the class. Hard to get much simpler than that.

Anyway, when the IDE opens a sketch, it opens tabs for all other files in the same directory, with known extensions, like .cpp, .c. .h. and .pde.

Header file extensions are generally .h, not .hpp.

Starting with, how do i use multiple source modules with the arduino environment? Do I have to build a library? There must be an easier way.

The IDE can allow you to have 'tabbed' code windows (see the far right arrow box just above the text window) . As long as you name them without a file extension name then the IDE will just append them altogether when it hands it all off to the compiler.

Lefty

PaulS: Anyway, when the IDE opens a sketch, it opens tabs for all other files in the same directory, with known extensions, like .cpp, .c. .h. and .pde.

Header file extensions are generally .h, not .hpp.

Okay I got that working thanks. Am I precluded from having an hpp extension? My source file says #include "polar.hpp" and the hpp file is in there with the source file, but the compiler fails to include it. For example, I get this error:

polar.cpp:1:21: error: polar.hpp: No such file or directory

The IDE mucks around copying your sketch into a temporary folder, and trying to guess what include files and other library code it needs. It looks like the .hpp extension is not supported. I can only suggest renaming as .h, or "manually" compiling using make, something I haven't been game to try yet. For example, in my case it is actually compiling:

/var/folders/1A/1AUycq24Ev4PKBlyDOFIG++++TI/-Tmp-/build7878823944259678721.tmp/Include_test.cpp

That is not where I put my source code. So unless it recognizes your include directive (or that is is including a file extension it knows about) it doesn't seem to either copy the .hpp file, or add its path to the include path, for the compile operation.

Yeah I renamed the file to polar.h but still no joy. I added an absolute path reference inside the include directive and that made it happy. Not the best solution. I see in the FAQ that I can program an Arduino in 100% C/C++ using AVR Studio, and I also see there is a plugin for Visual C++. So I may end up getting away fromt he Arduino IDE, although that's probably going to make other issues.

Thanks for the help everyone. Once I get past these few small issues it will probably move along quickly.