Native unit testing for mac M1: ar: no archive members specified

Hi, I’ve written some unit test to run on native platform, they run fine in windows but the same project gives error on my mac M1 machine:

Building...
ar: no archive members specified
usage:  ar -d [-TLsv] archive file ...
        ar -m [-TLsv] archive file ...
        ar -m [-abiTLsv] position archive file ...
        ar -p [-TLsv] archive [file ...]
        ar -q [-cTLsv] archive file ...
        ar -r [-cuTLsv] archive file ...
        ar -r [-abciuTLsv] position archive file ...
        ar -t [-TLsv] archive [file ...]
        ar -x [-ouTLsv] archive [file ...]

The project builds successfully for normal builds (i.e. ESP8266 and ESP32 builds with no unit testing)
command to run unit test is pio test -e native -f pg and native platform is defined as below

[env:native]
platform = native
build_type = debug
build_flags = -std=gnu++11
lib_compat_mode = off
lib_deps =
    rlogiacco/CircularBuffer @ ^1.3.3

src_filter = +<native/*>
debug_test = bparser

I’m using pio 5.2.0b1

Please show the output of the project task Advanced → Verbose Build and a tree of the project structure.

So I created a new project and it seems that adding rlogiacco/CircularBuffer @ ^1.3.3 to lib_deps causes the error, removing it fixes the error, but I dont know why since same project runs on windows without problem!
@maxgerhardt
project structure

src
--main.cpp
--native/main.cpp   

platformio.ini file

[platformio]
build_dir=.pioenvs
src_dir=src
build_cache_dir=.cache
default_envs=
  ; esp12e
  native


[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
src_filter = +<*> - <native/*>

[env:native]
platform = native
build_type = debug
build_flags = -std=gnu++11
lib_compat_mode = off
lib_deps =
    rlogiacco/CircularBuffer @ ^1.3.3

src_filter = +<native/*>

here is the verbose build result:

> Executing task: platformio run --verbose --environment native <

********************************************************************************************************************************
Obsolete PIO Core v5.1.1 is used (previous was 5.2.0b1)
Please remove multiple PIO Cores from a system:
https://docs.platformio.org/page/faq.html#multiple-platformio-cores-in-a-system
********************************************************************************************************************************
Processing native (platform: native; build_type: debug; build_flags: -std=gnu++11; lib_compat_mode: off; lib_deps: rlogiacco/CircularBuffer @ ^1.3.3; src_filter: +<native/*>)
--------------------------------------------------------------------------------------------------------------------------------
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ off
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CircularBuffer> 1.3.3 (/Users/ali/Documents/PlatformIO/Projects/esp_template/.pio/libdeps/native/CircularBuffer)
Building in debug mode
Retrieved `.pioenvs/native/src/native/main.o' from cache
ar rc .pioenvs/native/libcaf/libCircularBuffer.a
ar: no archive members specified
usage:  ar -d [-TLsv] archive file ...
        ar -m [-TLsv] archive file ...
        ar -m [-abiTLsv] position archive file ...
        ar -p [-TLsv] archive [file ...]
        ar -q [-cTLsv] archive file ...
        ar -r [-cuTLsv] archive file ...
        ar -r [-abciuTLsv] position archive file ...
        ar -t [-TLsv] archive [file ...]
        ar -x [-ouTLsv] archive [file ...]
*** [.pioenvs/native/libcaf/libCircularBuffer.a] Error 1
================================================== [FAILED] Took 0.46 seconds ==================================================

Environment    Status    Duration
-------------  --------  ------------
esp12e         IGNORED
native         FAILED    00:00:00.462
============================================ 1 failed, 0 succeeded in 00:00:00.462 ============================================
The terminal process "platformio 'run', '--verbose', '--environment', 'native'" terminated with exit code: 1.

src/native/main.cpp:

#include <stdio.h>
int main(void){
  printf("main ran\n");
  return 0;
}

This is a header only library, so since there are no c/cpp files, no .o object files will be created, and from no object files, no .a archive files can be created. So in that regards, the error is understandable.

does not have any .o following it.

Interesting that it fails differently on Windows and Mac. Can you open a CLI and execute pio upgrade --dev on both Windows & Mac machines? Do they still behave differently after a clean&rebuild?

Does adding

lib_archive = no

(docs) to the native env help? (Should prevent generation of the archive in the first place)

1 Like

@maxgerhardt thanks for shedding some light on this. now it makes some sense :smiley:
unfortunately most arduino libs are header only

I’m using same pio version on both windows and mac and already on dev channel 5.2.0b1
(can this be the reason?)[c - clang makefile "ar: no archive members specified" - Stack Overflow]

yes, this fixes the issue for me, :+1: , should I mark this as resolved when my problem is fixed but the issue still persists?

Hold up a second – here it says it’s using 5.1.1 and multiple cores are installed. That is bad. Can you try and get rid of the other cores and just have the latest-beta 5.2.0b1, verified by pio --version in the CLI?

I almost always use cli and didnt notice this warning, my error is also present when using cli which is 5.2.0b1, anyway I set
VSCode - Settings > Set platformio-ide.useBuiltinPIOCore to false. so VSCode is also using the global pio version and the warning disapeared

> Executing task: platformio run --verbose --environment native <

Processing native (platform: native; build_type: debug; build_flags: -std=gnu++11; lib_compat_mode: off; debug_test: pg; lib_deps: rlogiacco/CircularBuffer @ ^1.3.3; src_filter: +<native/*>)
--------------------------------------------------------------------------------------------------------------------------------
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ off
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CircularBuffer> 1.3.3 (/Users/ali/Documents/PlatformIO/Projects/esp_template/.pio/libdeps/native/CircularBuffer)
Building in debug mode
ar rc .pioenvs/native/libcaf/libCircularBuffer.a
ar: no archive members specified
usage:  ar -d [-TLsv] archive file ...
        ar -m [-TLsv] archive file ...
        ar -m [-abiTLsv] position archive file ...
        ar -p [-TLsv] archive [file ...]
        ar -q [-cTLsv] archive file ...
        ar -r [-cuTLsv] archive file ...
        ar -r [-abciuTLsv] position archive file ...
        ar -t [-TLsv] archive [file ...]
        ar -x [-ouTLsv] archive [file ...]
*** [.pioenvs/native/libcaf/libCircularBuffer.a] Error 1

Alright, then the issue is open at Don't create archive without object files · Issue #4019 · platformio/platformio-core · GitHub.

1 Like