sudar/Arduino-Makefile

Link to cpp files in subfolders

Closed this issue · 19 comments

It looks like cpp files in subfolders are ignored.

Would be possible to get these compiled and linked too? Subfoldering really helps when having lots of files :\

Regards.

this is pretty much the same as #249 - essentially using cpp/header files but not as libraries.

@roobre are you talking about something like that?

.
├── include
│   ├── LibOne
│   │   └── LibOne.h
│   ├── LibThree
│   │   └── LibThree.h
│   └── LibTwo
│       └── LibTwo.h
└── lib
    ├── LibOne
    │   └── LibOne.cpp
    ├── LibThree
    │   └── LibThree.cpp
    └── LibTwo
        └── LibTwo.cpp

@ladislas
In fact, I have something even simpler:

.
├── Libs1
│   └── LibOne.h
│   └── LibOne.cpp
│   └── LibTwo.h
│   └── LibTwo.cpp
├── Libs2
│   └── LibThree.h
│   └── LibThree.cpp

This is because they are not libraries, but suclasses, whose parent is on the same dir as the .ino file.

.h are included properly, but I got errors referring to missing function bodies, i.e., .cpp files are not being linked.

can you try putting Libs1 and Libs2 in a lib directory and setting USER_LIB_PATH = /path/to/lib in your Makefile?

ladislas' scenario will work if you set USER_LIB_PATH as he says, but neither scenario is very arduino-like or good c++, i don't think the ide would even see those libraries.

basically you can have libraries in ~/sketchbook/libraries/ or /usr/share/arduino/libraries/ or where USER_LIB_PATH is set to, and only one library per subdirectory.

on #249 there's a one-liner modification i made that would allow for multiple header .h files which is pretty standard c++ (use of includes) but multiple .cpp library files is a bit odd.

@ladislas I'll give a try to that.

@sej7278 I understand it's nor "good arduino" (good arduino almost doesn't include using cpp files) but I thought it would be conveniento to group my subclasses like that.

Ofc i could go for an include folder for .hs, but I thought this way would be simpler for the makefile. As it seems it doesn't, which directory structure do you suggest to allow grouping subclasses into directories?

you should put the LibOne.h and LibOne.cpp in the same LibOne directory inside the lib directory set by USER_LIB_PATH=/path/to/lib

But those aren't libraries, are subclasses. And one directory per
subclass seems a bit odd to me.

I think I'll try to patch the makefile myself and add an user-defined
array of extra directories to scan. I'll open a pull request when I
finish, just in case you are interested.

On 2014-09-07 16:42, Ladislas de Toldi wrote:

you should put the LibOne.h and LibOne.cpp in the same LibOne directory inside the lib directory set by USER_LIB_PATH=/path/to/lib

Reply to this email directly or view it on GitHub [1].

Links:

[1]
#251 (comment)

Kind of. But imagine one of your libraries, e.g., Motor, would have subclasses, like ServoMotor and ACMotor.

@roobre have you found a solution?

in my case, the class DriveSystem.h has a subclass called Motor.h and I put them in different directories. this allows me to use Motor somewhere else than just in DriveSystem

@roobre any news on the issue?

@roobre I am closing this ticket now because of inactivity.

Feel free to re-open if needed.

Hi everyone !
Same problem here.
I'm working on a medium sized arduino project. Here the explaination : the project use a LCD screen. To write on it, i've cut different states in something called "Menu". Each Menu is a class who define the behavior of each menus. Since a Menu is not the "core logic" of the app, i putted them into separated folder.
Headers files are compiled because i call them but it tell me an compilation error due to reference error on functions who are defined in .cpp.
And more I can't include cpp files from the header because i'm using forwarded class declarations.

Take a look here : https://github.com/martin-mh/Projet-SI-2015-2016/tree/a485d052c70d383b2369b381afd3dc0267d2156e

So i got to move everything in the root folder ! Here : https://github.com/martin-mh/Projet-SI-2015-2016

Do you have any work around or any fix for that ? Because having every files in the root folder is ugly, in my mind.
Thanks.

given that arduino-builder has just implemented recursively search subdirectories and totally broken itself (as it tries to link to the existing precompiled temp files!) i don't think its a good idea

ah darn ! That's not a big deal in anyway, don't worry :p

Any updates on that ? I would like as well to put source/headers files inside subfolders to organize code inside the library.

This is still an issue.

Having classes (note: classes, not libraries) split into .h and .cpp files might not be 'idiomatic Arduino', but it is completely expected idiomatic C++.

By not handling such cases, the IDE is crippling the experienced programmers who are using well-established good coding practices.

For anyone still wondering how to do this, I just uglily script it inside my makefile:

# This variable is local, name it however you want
SOURCE_FOLDERS = src src/Player src/Weapon

# These two are used by Arduino.mk
LOCAL_C_SRCS = $(foreach dir,$(SOURCE_FOLDERS),$(wildcard $(dir)/*.c))
LOCAL_CPP_SRCS = $(foreach dir,$(SOURCE_FOLDERS),$(wildcard $(dir)/*.cpp))

Hacky, but Just Works.