Giter Site home page Giter Site logo

Trouble with simple includes about ino HOT 13 CLOSED

amperka avatar amperka commented on August 18, 2024
Trouble with simple includes

from ino.

Comments (13)

rei-vilo avatar rei-vilo commented on August 18, 2024

Same problem for me: library not found.

I tried two cases:
1• the library is in the sketchbook/libraries user folder,
2• the library is in the project's src sub-folder.

Both return an error.

from ino.

zenoamaro avatar zenoamaro commented on August 18, 2024

It seems that ino fails when parsing the dependencies.d file, when multiple dependencies are given in a single line:

sketch.o: .build/src/sketch.cpp \
    /Applications/Arduino.app/.../arduino/Arduino.h \
    /Applications/Arduino.app/.../arduino/binary.h \
    ...
    /Applications/Arduino.app/.../arduino/new.h \
    /Applications/Arduino.app/.../standard/pins_arduino.h \
    lib/SSegs/SSegs.h lib/Framebuffer/Framebuffer.h lib/Metro/Metro.h

The problem is that match only matches the first occurence. Without changing the REs, the fix is as simple as this:

in commands/build.py:173

used_libs = set()
with open(output_filepath) as f:
    for line in f:
        matches = local_re.findall(line) or dist_re.findall(line)
        for match in matches:
            used_libs.add(match[0])

While using findall is not as nice as the regular match (as we lose references to named groups), it works. I'll provide a patch later.

from ino.

fabiankr avatar fabiankr commented on August 18, 2024

Did anyone get includes to work correctly? The pull request doesn't work for me.

from ino.

zenoamaro avatar zenoamaro commented on August 18, 2024

Here is a link to a test sketch that builds: test-sketch.zip

This is the sketch file tree:

test-sketch/
    lib/
        TestLib/
            TestLib.h
            TestLib.cpp
    src/
        sketch.ino

TestLib is simply imported as #include <TestLib.h>, as it will automatically be in the path.

from ino.

fabiankr avatar fabiankr commented on August 18, 2024

Okay, that works fine. But what about something like this:

test-sketch/
    lib/
    src/
        sketch.ino
        defines.h

There's no way to include defines.h in sketch.ino but this build fine using the official IDE. If you can help me to get it working, it'd be awesome.

from ino.

zenoamaro avatar zenoamaro commented on August 18, 2024

I'm sorry, I misunderstood your problem, I thought it was the same as mine.

Well, I know the official Arduino IDE concatenates all the tabs open in the project. Perhaps ino only concatenates multiple .ino files? I'll make some tests.

Regarding #including per se: it seems that the automagic build step moves sources around. If so, then a #define "lib.h" would search for the file in the wrong directory. I remember having witnessed this during my initial troubles with imports.

from ino.

rei-vilo avatar rei-vilo commented on August 18, 2024

I'm referring to the user-developped libraries, placed in the sketchbook/libraries folder.

The sketchbook directory is declared in the Preferences pane of the Arduino IDE.

The sub-folder called Libraries is included in the building process by default.

from ino.

fabiankr avatar fabiankr commented on August 18, 2024

@rei-vilo: You need to move the user-developed libraries to the lib subfolder.
@zenojevski: gcc searches for the headers in the current directory, but I don't understand the MakeFile.jinja code well enough to make it work correctly. Somewhere the header files need to be moved to the working directory of gcc...

from ino.

fabiankr avatar fabiankr commented on August 18, 2024

If you write #include "../../src/Defines.h" it works without problems. That means the .h files only need to be moved in the .build/src/ directory like the other files.
I don't know where ino does the copying of the files, but I will try to solve the issue now.

from ino.

fabiankr avatar fabiankr commented on August 18, 2024

There is now a working fork with simple includes: #20

from ino.

zenoamaro avatar zenoamaro commented on August 18, 2024

@fabiankr Here is a less invasive "fix" that allows importing from "src/" by adding it to the dependency scan. I've also added a few fixes and a test sketch a couple commits later.

If you could let me know if it works for your situation it'd be great.

from ino.

fabiankr avatar fabiankr commented on August 18, 2024

It works like a charm. I like your solution more, thanks. :)

from ino.

zenoamaro avatar zenoamaro commented on August 18, 2024

@fabiankr Thanks!

from ino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.