How to compile/link .c files from a subdir?

Hi. I’m trying to incorporate libbson into an Arduino project. I’d like to put all the libbson stuff into a bson/ directory alongside the sketch file, then compile & link everything in that directory with the sketch file.

I can get the sketch file itself to compile, but it looks like Arduino isn’t finding the bson/*.c files. Is there some way I can tell it to check that subdirectory?

Right now I’ve hacked it together with a bunch of symlinks, but I’d really prefer a better solution.

Along the same line: is there a way I can define a compiler directive, à la -DFOO=BAR or such such?

Thank you!

Please remember that C and C++ use different conventions for naming functions. To link from a C++ source file to a C library you have to tell the C++ compiler that the names use the C convention:

#extern “C” {
#include “somelib.h”
}

That’s from memory so I may be off a bit in the syntax.

You may also have to put the folder in a “src” folder in your sketch folder.

@johnwasser I’m already doing extern "C".

Are you saying I need my bson stuff in $SKETCH_DIR/src/bson/? So #include <bson/bson.h> would bring in $SKETCH_DIR/src/bson/bson.h?

worth a try.

Also try
$SKETCH_DIR/bson/src/bson.h
That's the organization for the library folders in the library hierarchy, so it may work the same.

Just a guess.

Alas, neither of these work. :frowning:

Is there maybe some interface for per-sketch customization of the compile & link options? (In my case that’s xtensa-esp32-elf-g++.)

(Update: apparently that can’t be done …)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.