Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current sketch dir to include path when compile library #5390

Closed
sadr0b0t opened this issue Sep 20, 2016 · 2 comments
Closed

Add current sketch dir to include path when compile library #5390

sadr0b0t opened this issue Sep 20, 2016 · 2 comments
Labels
Type: Duplicate Another item already exists for this topic

Comments

@sadr0b0t
Copy link

Hello,

I am writing a library for Arduino and I want to make it configurable at compile time with some defines in include file.

  1. Create library with module.h and module.cpp inside.
  2. Add #include"module_config.h" to my library module.cpp file (module_config.h file does not exist library dir)
  3. Create sketch using the library with #include"module.h".
  4. Create additional module_config.h file in sketch dir and put some defines inside.
  5. Try to compile the sketch and receive module_config.h not found compilation error from library files.

So I open
~/.arduino15/packages/arduino/hardware/avr/1.6.13/platform.txt

file and add -I{build.path}/sketch C++ compile option:

Compile c++ files

recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} -I{build.path}/sketch {includes} "{source_file}" -o "{object_file}"

At this time all compiles just fine.

I have taken this option from ChipKIT platform.txt, by the way:
http://chipkit.net/wiki/index.php?title=ChipKIT_core

@ReeceWeb
Copy link

ReeceWeb commented Mar 7, 2017

+1

This is a really important feature for library developers, since it allows compile-time optimizations based on conditional compilation without requiring the user to edit files in the library.

The include path search order should be: first the sketch dir, and then fall back to the library. This lets a library developer deliver a default version of the header inside the library. It would be used if the sketch does not provide one, and has the secondary advantage of serving as a template.

To make this more formal, perhaps introduce a new file extension like ".cfg" or ".libcfg"? Having a different extension allows the nice convention that if "libname.h" is the main include file for the library, then "libname.cfg" is the config file that goes with it. For bonus points, "Sketch->Include Library" could copy the "libname.cfg" from the requested library into the sketch to seamlessly provide a template ready for the user to edit.

@per1234 per1234 added the Type: Duplicate Another item already exists for this topic label Jul 5, 2017
@per1234
Copy link
Collaborator

per1234 commented Jul 5, 2017

+1

Closing as duplicate of #2547, which was in turn closed as a duplicate of the similar arduino/arduino-builder#15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Duplicate Another item already exists for this topic
Projects
None yet
Development

No branches or pull requests

3 participants