c++clangllvm

ld: warning: reexported library libunwind.1.dylib couldn't be matched with any parent library


I'm trying to setup a C++20 development environment on macOS Sonoma (14.6).

I have installed llvm and cmake with Homebrew. clang version info:

Homebrew clang version 18.1.8
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

C++ config in ~/.zshenv:

export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion)
path=('/opt/homebrew/opt/llvm/bin' $path)  # --> this is at the bottom of the file

The project has implementation and tests in one file and the directory structure looks like:

.
├── CMakeLists.txt
├── LICENSE.txt
├── Makefile
├── README.md
├── scripts
│   └── build.sh
└── src
    ├── foo
    │    ├── file1.cpp
    │    └── file2.cpp
    └── bar
         ├── file3.cpp
         └── file4.cpp

and CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.30)
project(algorithms)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

enable_testing()

# Find all source files recursively
file(GLOB_RECURSE SOURCE_FILES "src/**/*.cpp")

# Create executables for each source file
foreach(src_file ${SOURCE_FILES})
    # Extract file name without extension
    get_filename_component(exec_name ${src_file} NAME_WE)

    # Only create executables from files that contain a main function
    if(NOT "${exec_name}" STREQUAL "main")
        add_executable(${exec_name} ${src_file})

        # Register a test for each executable
        add_test(NAME ${exec_name} COMMAND ${exec_name})
    endif()
endforeach()

On executing the project, I'm seeing the below warning:

ld: warning: reexported library with install name '/opt/homebrew/opt/llvm/lib/libunwind.1.dylib' found at '/opt/homebrew/Cellar/llvm/18.1.8/lib/libunwind.1.0.dylib' couldn't be matched with any parent library and will be linked directly

I tried commenting out the export LDFLAGS directive in the .zshenv, but still see the same thing.

How can I fix this to get rid of the warning?


Solution

  • Updated LDFLAGSto:

    LDFLAGS+=" -L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib -lunwind"
    

    based on running brew info llvm.