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

Process precompiled and ldflags properties of library.properties #3994

Closed
maxgerhardt opened this issue Jul 4, 2021 · 1 comment
Closed
Labels
feature LDF Library Dependency Finder
Milestone

Comments

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Jul 4, 2021

What kind of issue is this?

  • [X ] Feature Request.
    Start by telling us what problem you’re trying to solve. Often a solution
    already exists! Don’t send pull requests to implement new features without first getting our
    support. Sometimes we leave features out on purpose to keep the project small.

Configuration

Operating system: Windows 10 x64

PlatformIO Version (platformio --version): PlatformIO Core, version 5.2.0a6

Description of problem

When using an Arduino library which makes use of a precompiled library, PlatformIO cannot compile them correctly without additional build_flags configuration, which is not needed for the Arduino IDE.

Refer e.g. https://community.platformio.org/t/how-to-debug-collect2-link-error-in-arduino-mkriotcarrier-example-sketch/22310 in which the library https://github.com/arduino-libraries/Arduino_MCHPTouch is used. This library contains in the library.properties

precompiled=true
ldflags=-lsamd21_qt_gcc

and the library file.

However, just using this library with

lib_deps =
     arduino-libraries/Arduino_MCHPTouch @ ^1.1.0

fails as PlatformIO does not process these flags.

Steps to Reproduce

  1. Create a new project for mkrwifi1010
  2. Add the Arduino_MCHPTouch via lib_deps
  3. Use example sketch as src\main.cpp
  4. Compile

Actual Results

Linking .pio\build\mkrwifi1010\firmware.elf
.pio\build\mkrwifi1010\lib29e\libArduino_MCHPTouch.a(touch.c.o): In function `touch_sensors_init':
touch.c:(.text.touch_sensors_init+0x12): undefined reference to `touch_selfcap_sensors_init_with_rs_table'
touch.c:(.text.touch_sensors_init+0x38): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0x56): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0x74): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0x92): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0xb0): undefined reference to `touch_selfcap_sensor_config'
touch.c:(.text.touch_sensors_init+0xbc): undefined reference to `touch_selfcap_sensors_calibrate'
.pio\build\mkrwifi1010\lib29e\libArduino_MCHPTouch.a(touch.c.o): In function `touch_sensors_measure':
touch.c:(.text.touch_sensors_measure+0x16): undefined reference to `touch_selfcap_sensors_measure'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\mkrwifi1010\firmware.elf] Error 1
=========== [FAILED] Took 4.18 seconds ===========

Expected Results

Successful compilation.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:mkrwifi1010]
platform = atmelsam
board = mkrwifi1010
framework = arduino
lib_deps =
     arduino-libraries/Arduino_MCHPTouch @ ^1.1.0

Source file to reproduce issue:

#include "Arduino_MCHPTouch.h"

void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ;
  // QTouch initialization
  if (!TOUCH.begin())
  {
    Serial.println("Error in sensors initialization!");
    while (1)
      ;
  }
  Serial.println("Touch initialization Done!");
}

void loop()
{
  // polling the sensor for new data
  TOUCH.poll();

  // Checks if new data are available
  if (TOUCH.available())
  {
    //reads senseors
    Serial.print("Sensor 1 status: ");
    Serial.println(TOUCH.read(0));
    Serial.print("Sensor 2 status: ");
    Serial.println(TOUCH.read(1));
    Serial.print("Sensor 3 status: ");
    Serial.println(TOUCH.read(2));
    Serial.print("Sensor 4 status: ");
    Serial.println(TOUCH.read(3));
    Serial.print("Sensor 5 status: ");
    Serial.println(TOUCH.read(4));
    Serial.println();
  }
  delay(100);
}

Additional info

After adding

build_flags =
    -L"$PROJECT_LIBDEPS_DIR/$PIOENV/Arduino_MCHPTouch/src/cortex-m0plus"
    -lsamd21_qt_gcc 

compilation is successful.

Linking .pio\build\mkrwifi1010\firmware.elf
Checking size .pio\build\mkrwifi1010\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   8.6% (used 2816 bytes from 32768 bytes)
Flash: [=         ]   8.2% (used 21564 bytes from 262144 bytes)
Building .pio\build\mkrwifi1010\firmware.bin
=========== [SUCCESS] Took 2.92 seconds ===========
@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Jul 4, 2021

Implementing this would also make many library.json and extra scripts unnecessary, as e.g. used in https://github.com/BoschSensortec/BSEC-Arduino-library. Note that the Arduino IDE seems to use src/<CPU architecture> as the linker path directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature LDF Library Dependency Finder
Projects
None yet
Development

No branches or pull requests

2 participants