Go Down

Topic: Sketch file/directory name problem with separate source file of the same name (Read 2674 times) previous topic - next topic

Jeff Rowberg

I have a problem that may not be solvable based on the way the Arduino IDE is made, but I want to double-check here. I have searched all over the place and so far haven't come up with anything, but I have a suspicion based on my own testing.

Here's the situation: I have a class library with a bunch of source files that are stored in subdirectories like so:

/ADXL345/ADXL345.cpp
/ADXL345/ADXL345.h

/MPU6050/MPU6050.cpp
/MPU6050/MPU6050.h

/AK8975/AK8975.cpp
/AK8975/AK8975.h

...and so on. What I want to do is create a demo file for each of these classes, something like so:


/ADXL345/ADXL345.cpp
/ADXL345/ADXL345.h
/ADXL345/ADXL345.ino

/MPU6050/MPU6050.cpp
/MPU6050/MPU6050.h
/MPU6050/MPU6050.ino

/AK8975/AK8975.cpp
/AK8975/AK8975.h
/AK8975/AK8975.ino

I'm using Arduino RC1, hence the .ino extension. I think the same problem I'm having applies in v0022 with .pde as well. Anyway, what's happening is that it appears the "MPU6050.cpp" file (for instance) is causing the entire contents of the "MPU6050.ino" file to be ignored. I get the following error when I try to compile:

Code: [Select]
core.a(main.cpp.o): In function `main':
C:\arduino-1.0-rc1\hardware\arduino\cores\arduino/main.cpp:12: undefined reference to `setup'
C:\arduino-1.0-rc1\hardware\arduino\cores\arduino/main.cpp:15: undefined reference to `loop'


Those functions are definitely present in the .ino file, but the're invisible for some reason. However, if I add the following lines to the "MPU6050.cpp" file:

Code: [Select]
void setup() { }
void loop() { }


Everything compiles just fine. It doesn't do what it's supposed to when it runs, obviously, but it does compile. So here's my theory: you can't have a sketch file with the same name (without the .ino extension) as another .cpp source file within the sketch. Is this true? If so, can it be fixed? If not, is there a way to do what I'm trying to do that does not involve changing the parent folder names so that the folder name and sketch filename don't overlap with the class source filenames? I could do something like this:

/MPU6050_lib/MPU6050.cpp
/MPU6050_lib/MPU6050.h
/MPU6050_lib/MPU6050_lib.ino

...but I'd rather not if I can avoid it. It seems like a really lame solution to a similarly lame problem, and there are at least a few links to these source files on Github that point to the non-modified folders.

Any thoughts are welcome!

    Jeff

johnwasser

Try:

Arduino/libraries/ADXL345/ADXL345.cpp
Arduino/libraries/ADXL345/ADXL345.h
Arduino/libraries/ADXL345/Examples/ADXL345/ADXL345.ino

Arduino/libraries/MPU6050/MPU6050.cpp
Arduino/libraries/MPU6050/MPU6050.h
Arduino/libraries/MPU6050/Examples/MPU6050/MPU6050.ino

Arduino/libraries/AK8975/AK8975.cpp
Arduino/libraries/AK8975/AK8975.h
Arduino/libraries/AK8975/Examples/AK8975/AK8975.ino

Sketch directories in the Examples subdirectory of a library director appear in the Files->Examples->libraryname menu
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

Jeff Rowberg


Try:

Arduino/libraries/ADXL345/ADXL345.cpp
Arduino/libraries/ADXL345/ADXL345.h
Arduino/libraries/ADXL345/Examples/ADXL345/ADXL345.ino
...
Sketch directories in the Examples subdirectory of a library director appear in the Files->Examples->libraryname menu


Thanks! That is an interesting approach. The way this is built though, that doesn't quite fit with the logical arrangement of the library (you can see the structure on Github here). Basically, the real "library" is made up of the I2Cdev.cpp and I2Cdev.h files. This part is working correctly when I install it as either a built-in or user-contributed library. The I2Cdev class provides a single static reusable set of functions for the individual device libraries to use themselves.

However, the actual device classes (ADXL345, AK8975, MPU6050, etc.) are not bundled into the same library, since you're supposed to just pick and choose which devices you need and only use those files, for simplicity.

...though, as I'm writing this, I certainly could write the examples as though each device was its own library, which would work for the Arduino IDE at least, even if it's slightly more messy than I originally hoped. Hmm.

Good idea!

Go Up