including an .a library in the build

I try to use the Bosch BSEC_Software_Library for the BME680 sensor. To use their library libalgobsec.a it is advised to modify the platform.txt file.

The modifcations they sugest do not work:

These can be overridden in platform.local.txt

compiler.c.extra_flags=
compiler.c.elf.extra_flags=
->#compiler.c.elf.extra_flags=-v
compiler.cpp.extra_flags=
compiler.S.extra_flags=
compiler.ar.extra_flags=
compiler.elf2hex.extra_flags=
->compiler.libraries.ldflags=

In the end I decided to look at the command line and edit directly what is input there:

Combine gc-sections, archives, and objects

recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags}
-mmcu={build.mcu} {compiler.c.elf.extra_flags}
-o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}"
/Users/marijn/Documents/Arduino/libraries/BSEC_Software_Library/src/atmega2560/libalgobsec.a "-L{build.path}" -lm

and delete the other modifications.

It is not pretty but it works. Other code still compiles and the basic.ino example from Bosch works too.

can I put this in a platform.local.txt? And where should I put that file?
Is there an other solution to this problem?

marijn:
The modifcations they sugest do not work:

Which version of the Arduino IDE are you using?
Are you compiling for the Mega 2560?
By "do not work", do you mean there is an error when you try to compile the sketch?

marijn:
can I put this in a platform.local.txt?

Yes.

marijn:
And where should I put that file?

In the same folder as the platform.txt file. Note that you'll need to redo this every time you update to a new version of the hardware package. Also note that the copy of the Arduino AVR Boards package that is located under the Arduino IDE installation folder will no longer be in use after you update Arduino AVR Boards via Boards Manager, so make sure you are putting your platform.local.txt in the right place.

marijn:
Is there an other solution to this problem?

I don't have much experience with using precompiled libraries, but I have managed to get it working fine without any goofy workarounds like what you resorted to. I'm happy to investigate this, but I don't own a BME680. So if it's a matter of "do not work" meaning that it won't compile, I can look into it, but if it's a matter of the sketch compiling but not working as expected then I'm more limited.

Thank you for your quick response.

Ok when I revert to the platform.txt Bosch sugest and I compile basic.ino this is the result(removed first part to comply with the 9000 chars rule):

Linking everything together...
/Users/marijn/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--relax -mmcu=atmega2560 {compiler.c.elf.extra_flags} -o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/basic.ino.elf /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/sketch/basic.ino.cpp.o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/libraries/BSEC_Software_Library/bsec.cpp.o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/libraries/BSEC_Software_Library/bme680/bme680.c.o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/libraries/Wire/Wire.cpp.o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/libraries/Wire/utility/twi.c.o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/libraries/SPI/SPI.cpp.o /var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338/../arduino_cache_816138/core/core_arduino_avr_mega_cpu_atmega2560_354614c5233f58b3a5744826db5a4bbd.a -L/var/folders/fh/rsttw1f90zq8_hcbqp16jlw40000gn/T/arduino_build_27338 -lm
avr-gcc: error: {compiler.c.elf.extra_flags}: No such file or directory
Multiple libraries were found for "bsec.h"
 Used: /Users/marijn/Documents/Arduino/libraries/BSEC_Software_Library
Multiple libraries were found for "Wire.h"
 Used: /Users/marijn/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/libraries/Wire
Multiple libraries were found for "SPI.h"
 Used: /Users/marijn/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/libraries/SPI
Using library BSEC_Software_Library at version 1.4.703 in folder: /Users/marijn/Documents/Arduino/libraries/BSEC_Software_Library 
Using library Wire at version 1.0 in folder: /Users/marijn/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/libraries/Wire 
Using library SPI at version 1.0 in folder: /Users/marijn/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/libraries/SPI 
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

So the sketch will not compile.

the Bosch library can be found here:

And for anyone wanting to try this sensor:
The libraries, like the one from adafruit, use bme680.c in their core from bosch. The routines for temprature, pressure and humidity are fine. The routine for Rgas has a large temperature error. It makes te sensor unusable for any enviroment with temperature swings of more then a few degrees centigrade. Like this at 12C Rgas=85.2kOhm at 15C Rgas = 62.1kOhm. I have done this from -20 to +35C The curve is fairly straight, but I would like to use a better compensated library.

marijn:

avr-gcc: error: {compiler.c.elf.extra_flags}: No such file or directory

This error is caused by not having a definition of compiler.c.elf.extra_flags in your platform.txt file. The entries provided in the library instructions do have this, but it is a bit confusing because they also have a commented out definition, so maybe you thought that meant you were supposed to comment out the existing definition in platform.txt. So make sure your platform.txt has this line:

compiler.c.elf.extra_flags=

It's annoying because that property didn't need any modifications anyway. It looks like they had been messing about with it to get verbose output for troubleshooting, then posted their non-standard platform.txt snippet with unnecessary modifications and pointless commented out lines instead of posting a snippet from a stock platform.txt with only the single necessary line added. It would be understandable if it's just some random hobbyist flailing about with some amateur code they wrote on the weekend, but this is a library written by Bosch to support a product they manufacture!

They now mention that you need to modify recipe.c.combine.pattern, but they neglect to say how this needs to be done on the Arduino AVR Boards platform.txt. Well, I'm a bit more considerate than our good friends at Bosch. So here's the line you need to replace it with for AVR:

recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} "{build.path}/{archive_file}" "-L{build.path}" -lm

Oh great it works!!!

While searching for a solution I found others who used a make script to compile. My OS is too old to make that solution work.

I think some intern at Bosch made the arduino libraries. Look at this one:

 * @file bme680_data.h
 * @date 31 Jan 2018
 * @version 1.0
 *
 */

//#ifndef BME680_CLASS_H
//#define BME680_CLASS_H

/* Includes */
#include "Arduino.h"
#include "Wire.h"
#include "SPI.h"
#include "bme680\bme680.h"

On some systems a \ or a / does not matter much. OSX however is very particulair in that. Tried to find a person at Bosch to mail about that bug but ony found their regulair mail address.

Thanks again.

marijn:
Oh great it works!!!

I'm very glad to hear it!

marijn:
While searching for a solution I found others who used a make script to compile. My OS is too old to make that solution work.

I'm surprised. I'd expect make to more accommodating to an old OS than the Arduino IDE. I have some experience with make, and it's great in it's own way, but I have no interest in using it with Arduino sketches. My limited experience with the popular Arduino makefiles is that they don't quite work the same as the Arduino IDE, so you end up with some sketches and libraries that are not compatible, and then it's a big hassle trying to figure out what went wrong and how to fix it. That defeats the whole purpose of Arduino. If I wanted to go down that path, I'd abandon the Arduino framework altogether (which I'll never do).

marijn:
On some systems a \ or a / does not matter much. OSX however is very particulair in that.

Yes, that's very annoying. I see this sort of thing in Arduino projects often. The developer is using Windows, so it works fine for them, but then some beginner tries it on a different OS and has a bad day.

Where did you find that code? If it's in a GitHub repository, I'll submit a pull request to fix the bug. I generally have good results with that approach. I rarely will bother to report bugs to an email address because I've found it usually is just a waste of time.