When using vscode on osx, and when installing compilers via brew, the configuration fails to configure CMAKE_AR which causes incompatibilities between .a files and their consumers.
Output like this is indicative:
[build] ld: warning: ignoring file lib/libgmock_main.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 )
The same system can build successfully by manually setting CMAKE_AR.
Steps to Reproduce (OSX-only bug)
install xcode on your system
brew install gcc
brew install llvm
create a C++ project that creates .a files and links these into an executable.
select "scan for kits" in the cmake tools build kits menu. It should find the version of llvm installed by brew.
Select the llvm version discovered in the brew keg directory (/usr/local/opt)
configure and build
Expected
Build is successful.
Actual
the linker ignores the .a files because it does not recognize their format.
Notice the use of /usr/local/opt/binutils/bin/ar in this command. This should be /usr/local/opt/llvm/bin/llvm-ar.
### Additional Information
Using this toolchain file works around the issue:
#
# Copyright (C) OpenCyphal Development Team <opencyphal.org>
# Copyright Amazon.com Inc. or its affiliates.
# SPDX-License-Identifier: MIT
#
set(CMAKE_CXX_COMPILER_ID "Clang")
set(CMAKE_C_COMPILER_ID "Clang")
set(CMAKE_C_COMPILER /usr/local/opt/llvm/bin/clang)
set(CMAKE_CXX_COMPILER /usr/local/opt/llvm/bin/clang++)
set(CMAKE_ASM_COMPILER /usr/local/opt/llvm/bin/clang)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_LINKER_FLAGS_INIT
"-L/usr/local/opt/llvm/lib/c++ -Wl,-rpath,/usr/local/opt/llvm/lib/c++ -L/usr/local/opt/llvm/lib"
)
set(CMAKE_C_LINKER_FLAGS_INIT
"-L/usr/local/opt/llvm/lib/c -Wl,-rpath,/usr/local/opt/llvm/lib/c -L/usr/local/opt/llvm/lib"
)
set(CMAKE_CXX_FLAGS_INIT
"-I/usr/local/opt/llvm/include"
)
# The auto-scan for tools in vscode fails to properly setup the AR tool. This
# toolchain file fixes that.
set(CMAKE_AR /usr/local/opt/llvm/bin/llvm-ar)
Brief Issue Summary
When using vscode on osx, and when installing compilers via brew, the configuration fails to configure
CMAKE_AR
which causes incompatibilities between .a files and their consumers.Output like this is indicative:
The same system can build successfully by manually setting
CMAKE_AR
.Steps to Reproduce (OSX-only bug)
/usr/local/opt
)Expected
Build is successful.
Actual
the linker ignores the .a files because it does not recognize their format.
CMake Tools Diagnostics
Notice the use of
/usr/local/opt/binutils/bin/ar
in this command. This should be/usr/local/opt/llvm/bin/llvm-ar
.