Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen3 fails to find standard math library on MacOS #4526

Closed
rlorigro opened this issue Jan 28, 2025 · 1 comment
Closed

Eigen3 fails to find standard math library on MacOS #4526

rlorigro opened this issue Jan 28, 2025 · 1 comment
Assignees
Labels
Build: CMake CMake based build issue Help Needed Modeling/Usage problem OS: Mac MacOS
Milestone

Comments

@rlorigro
Copy link

rlorigro commented Jan 28, 2025

What version of OR-Tools and what language are you using?
Version: https://github.com/google/or-tools/archive/refs/tags/v9.10.tar.gz
Language: C++

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
Any

What operating system (Linux, Windows, ...) and version?

-- CMAKE_CXX_COMPILER_ID: AppleClang
-- CMAKE_CXX_COMPILER_VERSION: 16.0.0.16000026
-- CMAKE_SYSTEM: Darwin-23.6.0

Apple M1
14.7.2 (23H311)

What did you do?
Steps to reproduce the behavior:
Attempt to build on my system using FetchContent:

    include(FetchContent)
    FetchContent_Declare(
            ortools
            URL https://github.com/google/or-tools/archive/refs/tags/v9.10.tar.gz
    )

    set(BUILD_DEPS ON)
    set(BUILD_DOC OFF)
    set(BUILD_SAMPLES OFF)
    set(BUILD_EXAMPLES OFF)
    set(USE_COINOR OFF)
    set(USE_HIGHS OFF)
    FetchContent_MakeAvailable(ortools)

    include_directories(
            ${ortools_SOURCE_DIR}
            ${ortools_BINARY_DIR}
            ${absl_SOURCE_DIR}
            ${protobuf_SOURCE_DIR}/src
    )

    add_dependencies(sv_merge ortools)

What did you expect to see
No CMake errors

What did you see instead?
Cmake Errors:

CMake Error at build/_deps/eigen3-src/CMakeLists.txt:114 (message):
  Can't link to the standard math library.  Please report to the Eigen
  developers, telling them about your platform.

this is the code that fails:

find_package(StandardMathLibrary)


set(EIGEN_TEST_CUSTOM_LINKER_FLAGS  "" CACHE STRING "Additional linker flags when linking unit tests.")
set(EIGEN_TEST_CUSTOM_CXX_FLAGS     "" CACHE STRING "Additional compiler flags when compiling unit tests.")

set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")

if(NOT STANDARD_MATH_LIBRARY_FOUND)

  message(FATAL_ERROR
    "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.")

else()

  if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
    set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}")
  else()
    set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}")
  endif()

endif()

despite CMake finding the library, when prompted manually:

find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
    message(STATUS "Found math library: ${MATH_LIBRARY}")
else()
    message(FATAL_ERROR "Math library not found")
endif()

yields:

-- Found math library: /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/lib/libm.tbd

Anything else we should know about your project / environment

I had a long convo with ChatGPT about this and was not able to resolve it, but it gave me this feedback, which may be useful:

Based on the output, we can see the following:

CMake is finding the math library (libm) at the location /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/lib/libm.tbd, which is a text-based stub (.tbd), a common way that macOS packages system libraries, especially for SDKs.

This libm.tbd is a stub library rather than a fully linked dynamic library (.dylib), and this could explain the confusion or linking issues you're experiencing.

What is a .tbd file?

.tbd (text-based stub) files in macOS are metadata files that tell the linker where to find the actual dynamic libraries (.dylib) at runtime. The fact that it’s a .tbd file indicates that macOS is providing the math library as a stub, which should be resolved at link time, but it may not be resolving correctly in this case.

I also tried a variety of other solutions, like finding the library and then setting some env variables that Eigen CMake uses, to no avail.

@rlorigro
Copy link
Author

Nevermind, it seems my cpp libraries are broken after an update

@Mizux Mizux self-assigned this Jan 29, 2025
@Mizux Mizux added Help Needed Modeling/Usage problem OS: Mac MacOS Build: CMake CMake based build issue labels Jan 29, 2025
@Mizux Mizux added this to the v9.12 milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build: CMake CMake based build issue Help Needed Modeling/Usage problem OS: Mac MacOS
Projects
None yet
Development

No branches or pull requests

2 participants