platformio / platform-native

Native: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/native
Apache License 2.0
21 stars 27 forks source link

Building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format #11

Closed Lucianovici closed 2 years ago

Lucianovici commented 3 years ago

Hi,

I am trying the official example https://github.com/platformio/platformio-examples/tree/develop/unit-testing/calculator

➜  calculator git:(develop) pio test -v -e native
Collected 3 items

Processing test_common in native environment
----------------------------------------------------------------------------------------------------
Building...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <calculator> (/Users/lucian/Projects/open/platformio-examples/unit-testing/calculator/lib/calculator)
Building in release mode
g++ -o .pio/build/native/program .pio/build/native/test/test_common/test_calculator.o .pio/build/native/test/tmp_pio_test_transport.o -L.pio/build/native .pio/build/native/lib40d/libcalculator.a .pio/build/native/libUnityTestLib.a
ld: warning: ignoring file .pio/build/native/lib40d/libcalculator.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file .pio/build/native/libUnityTestLib.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture x86_64:
  "_UnityAssertEqualNumber", referenced from:
      test_function_calculator_addition() in test_calculator.o
      test_function_calculator_subtraction() in test_calculator.o
      test_function_calculator_multiplication() in test_calculator.o
      test_function_calculator_division() in test_calculator.o
  "_UnityBegin", referenced from:
      process() in test_calculator.o
  "_UnityDefaultTestRun", referenced from:
      process() in test_calculator.o
  "_UnityEnd", referenced from:
      process() in test_calculator.o
  "Calculator::add(int, int)", referenced from:
      test_function_calculator_addition() in test_calculator.o
  "Calculator::div(int, int)", referenced from:
      test_function_calculator_division() in test_calculator.o
  "Calculator::mul(int, int)", referenced from:
      test_function_calculator_multiplication() in test_calculator.o
  "Calculator::sub(int, int)", referenced from:
      test_function_calculator_subtraction() in test_calculator.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** [.pio/build/native/program] Error 1
==================================== [FAILED] Took 0.63 seconds ====================================

Processing test_desktop in native environment
----------------------------------------------------------------------------------------------------
Building...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <calculator> (/Users/lucian/Projects/open/platformio-examples/unit-testing/calculator/lib/calculator)
Building in release mode
g++ -o .pio/build/native/program .pio/build/native/test/test_desktop/test_calculator.o .pio/build/native/test/tmp_pio_test_transport.o -L.pio/build/native .pio/build/native/lib40d/libcalculator.a .pio/build/native/libUnityTestLib.a
ld: warning: ignoring file .pio/build/native/lib40d/libcalculator.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file .pio/build/native/libUnityTestLib.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture x86_64:
  "_UnityAssertEqualNumber", referenced from:
      test_function_calculator_addition() in test_calculator.o
      test_function_calculator_subtraction() in test_calculator.o
      test_function_calculator_multiplication() in test_calculator.o
      test_function_calculator_division() in test_calculator.o
  "_UnityBegin", referenced from:
      _main in test_calculator.o
  "_UnityDefaultTestRun", referenced from:
      _main in test_calculator.o
  "_UnityEnd", referenced from:
      _main in test_calculator.o
  "Calculator::add(int, int)", referenced from:
      test_function_calculator_addition() in test_calculator.o
  "Calculator::div(int, int)", referenced from:
      test_function_calculator_division() in test_calculator.o
  "Calculator::mul(int, int)", referenced from:
      test_function_calculator_multiplication() in test_calculator.o
  "Calculator::sub(int, int)", referenced from:
      test_function_calculator_subtraction() in test_calculator.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** [.pio/build/native/program] Error 1
==================================== [FAILED] Took 0.66 seconds ====================================

Test           Environment    Status    Duration
-------------  -------------  --------  ------------
test_common    uno            IGNORED
test_common    nodemcu        IGNORED
test_common    native         FAILED    00:00:00.631
test_desktop   uno            IGNORED
test_desktop   nodemcu        IGNORED
test_desktop   native         FAILED    00:00:00.660
test_embedded  uno            IGNORED
test_embedded  nodemcu        IGNORED
test_embedded  native         IGNORED
============================== 2 failed, 0 succeeded in 00:00:01.291 ==============================

I'm using macOS Catalina 10.15.7, and my gcc version is:

➜  calculator git:(develop) gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Any suggestion is more than welcome. Thank you!

Lucianovici commented 3 years ago

I am using the latest pio and native.

➜  calculator git:(develop) pio --version
PlatformIO Core, version 5.0.4

➜  calculator git:(develop) pio platform install "native"
Platform Manager: native @ 1.1.3 is already installed
The platform 'native' has been successfully installed!
The rest of the packages will be installed later depending on your build environment.
mh- commented 3 years ago

Are you using ar and ranlib from Apple as well? I had GNU versions of these tools, which caused the same problem. See also https://community.platformio.org/t/native-desktop-unit-testing-on-macos/20416 Making sure that the Apple versions of ar and ranlib are used, and then

rm -rf .pio/build
pio test

helped in my case.

brunobasto commented 3 years ago

Making sure that the Apple versions of ar and ranlib are used?

how do we make sure it uses ar instead of gcc? Where can we configure that?

ivankravets commented 2 years ago

Please upgrade to the latest PIO Core via pio upgrade --dev. Should be fixed.

lrascao commented 2 years ago

FYI, i'm on PlatformIO Core, version 6.1.3 on MacOS and also ran into this, only after changing PATH to use /usr/bin/ar and/usr/bin/ranlib does the error go away