aditya0yadav commented on PR #18331:
URL: https://github.com/apache/nuttx/pull/18331#issuecomment-3868579882
I managed to get the build working on macOS with the following tweaks. The
primary issue stems from the build system attempting to use GCC-specific flags
(`-fprofile-arcs`, `-lgcov`) on a host where **Apple Clang** is the primary
toolchain.
While the build now completes, there are some remaining symbol conflicts.
Currently, the Clang linker is resolving these "multiple definition" issues
permissiveley, but we should eventually address the root cause to ensure the
binary is fully stable and portable across different host environments.
---
### **Proposed Fixes**
#### **1. Toolchain Logic Update**
**File:** `arch/sim/src/cmake/Toolchain.cmake`
Updated to prioritize native Clang on macOS and swap to LLVM-native coverage
instrumentation.
```cmake
if(APPLE)
# If we haven't forced GCC, default to the native Apple Clang
if(NOT CONFIG_SIM_TOOLCHAIN_GCC)
set(CONFIG_SIM_TOOLCHAIN_CLANG y)
endif()
# Only look for this if we aren't using native Clang
if(NOT CONFIG_SIM_TOOLCHAIN_CLANG)
find_program(CMAKE_C_ELF_COMPILER x86_64-elf-gcc)
find_program(CMAKE_CXX_ELF_COMPILER x86_64-elf-g++)
endif()
endif()
# ...
if(CONFIG_COVERAGE_ALL)
if(APPLE)
# Use Clang native coverage for Mac
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate)
else()
# Keep GCC flags for Linux/Windows
add_compile_options(-fprofile-arcs -ftest-coverage)
add_link_options(--coverage)
endif()
endif()
```
#### **2. External Library Linking**
**File:** `arch/sim/src/sim/CMakeLists.txt`
Prevent the linker from searching for `libgcov` on macOS, as profiling is
handled by the Clang runtime.
```cmake
if(CONFIG_COVERAGE_TOOLCHAIN)
if(NOT APPLE)
list(APPEND STDLIBS gcov)
endif()
endif()
```
#### **3. Legacy Makefile Compatibility**
**File:** `arch/sim/src/Makefile`
Ensuring the legacy build path also respects the macOS library constraints.
```makefile
ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y)
ifneq ($(CONFIG_HOST_MACOS),y)
STDLIBS += -lgcov
endif
endif
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]