Cannot link compiled static C-libraries

I’m attempting to combine QTouch and Arduino for a project using an Arduino Nano 33 IoT. I’ve generated the QTouch files which include static c-libraries that must be included. However, the compiler is unable to find the files, even though I explicitly tell it where to find them with build_flags.

Here is my platformio.ini file:

[env:nano_33_iot]
platform = atmelsam
board = nano_33_iot
framework = arduino
build_flags = -w -Ilib -Llib -lqtm_acq_samd21_0x0024_api -lqtm_freq_hop_0x0006_api -lqtm_freq_hop_auto_0x0004_api -lqtm_touch_key_0x0002_api

And the structure of the lib directory on my Windows machine:

08/01/2023  10:07 AM             6,992 qtm_acq_samd21_0x0024_api.a
08/01/2023  10:07 AM            16,198 qtm_acq_samd21_0x0024_api.h
08/01/2023  10:07 AM             7,212 qtm_common_components_api.h
08/01/2023  10:07 AM             1,704 qtm_freq_hop_0x0006_api.a
08/01/2023  10:07 AM             4,681 qtm_freq_hop_0x0006_api.h
08/01/2023  10:07 AM             1,996 qtm_freq_hop_auto_0x0004_api.a
08/01/2023  10:07 AM             4,952 qtm_freq_hop_auto_0x0004_api.h
08/01/2023  10:07 AM             3,900 qtm_touch_key_0x0002_api.a
08/01/2023  10:07 AM            10,231 qtm_touch_key_0x0002_api.h

And, finally, the error I am getting:

Linking .pio\build\nano_33_iot\firmware.elf
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lqtm_acq_samd21_0x0024_api
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lqtm_freq_hop_0x0006_api
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lqtm_freq_hop_auto_0x0004_api
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lqtm_touch_key_0x0002_api
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nano_33_iot\firmware.elf] Error 1

I am importing the touch library in my main.cpp file:

extern "C" {
    #include "touch/touch.h"
}

which imports the above qtm_* files directly, or through another sub-import.

Any ideas as to why this is happening?

These files don’t conform to the right naming scheme at all. If you tell GCC to

-lqtm_freq_hop_auto_0x0004_api

It will look for a library called libqtm_freq_hop_auto_0x0004_api.a. And that doesn’t exist.

Refer to this to link with the full name: You’ll have to write -l:qtm_freq_hop_auto_0x0004_api.a etc.

Thanks for the reply.

Unfortunately, I’m still getting the same error. Here’s my updated platformio.ini file for reference:

[env:nano_33_iot]
platform = atmelsam
board = nano_33_iot
framework = arduino
build_flags = -w -Ilib -Llib -l:qtm_acq_samd21_0x0024_api.a -l:qtm_freq_hop_0x0006_api.a -l:qtm_freq_hop_auto_0x0004_api.a -l:qtm_touch_key_0x0002_api.a

Yeah I just tested that and unfortunately the bug Failing to link external library - #5 by vit is still present. You have to write .a.a instead of .a as a workaround because it strips one .a. I just tested that in a minimal project and it does work fine.

Alternatively, prefixing the produced .a files with lib also solves your problem and your original platformio.ini can be used.

That worked!

Thanks for the help!