Skip to content

Could not find COCOA_LIBRARY using the following names: Cocoa #1748

Closed

Description

@fatduckling

Godot version

4.4

godot-cpp version

6388e26

System information

Ubuntu

Issue description

Hi,

I'm using osxcross to compile godot-cpp for MacOS and iOS. I just upgraded from Godot 4.3 (which was working fine) to 4.4 and I am getting this error:

CMake Error at cmake/macos.cmake:22 (find_library):
  Could not find COCOA_LIBRARY using the following names: Cocoa
Call Stack (most recent call first):
  cmake/godotcpp.cmake:25 (include)
  CMakeLists.txt:43 (include)

This is my compile command:

AR=x86_64-apple-$OSXCROSS_TARGET-ar \
CC=x86_64-apple-$OSXCROSS_TARGET-clang \
CODESIGN_ALLOCATE=$OSXCROSS_ROOT/target/bin/x86_64-apple-$OSXCROSS_TARGET-codesign_allocate \
CPLUS_INCLUDE_PATH=$OSXCROSS_ROOT/target/include \
CXX=x86_64-apple-$OSXCROSS_TARGET-clang++ \
C_INCLUDE_PATH=$OSXCROSS_ROOT/target/include \
HOST=x86_64-apple-$OSXCROSS_TARGET \
LIBRARY_PATH=$OSXCROSS_ROOT/target/libx86_64 \
PATH=$OSXCROSS_ROOT/target/bin:$PATH \
RANLIB=x86_64-apple-$OSXCROSS_TARGET-ranlib \
x86_64-apple-$OSXCROSS_TARGET-cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-Ofast" \
-DCMAKE_C_FLAGS="-Ofast" \
-DCMAKE_INSTALL_DOCDIR=/tmp/godotcpp/build_MACOS_X86_64 \
-DCMAKE_INSTALL_LIBDIR=libx86_64 \
-DCMAKE_INSTALL_MANDIR=/tmp/godotcpp/build_MACOS_X86_64 \
-DCMAKE_INSTALL_PREFIX=$OSXCROSS_ROOT/target \
-DAPPLE=1 \
-DGODOT_CPP_WARNING_AS_ERROR=OFF \
-DGODOT_CPP_SYSTEM_HEADERS=ON \
-DFLOAT_PRECISION=single \
-B /tmp/godotcpp/build_MACOS_X86_64 \
/tmp/godotcpp

I can see the Cocoa framework is installed:

$ tree $SDKROOT/System/Library/Frameworks/Cocoa.framework
/opt/osxcross/target/SDK/MacOSX15.1.sdk/System/Library/Frameworks/Cocoa.framework
|-- Cocoa.tbd -> Versions/Current/Cocoa.tbd
|-- Headers -> Versions/Current/Headers
|-- Modules -> Versions/Current/Modules
`-- Versions
    |-- A
    |   |-- Cocoa.tbd
    |   |-- Headers
    |   |   `-- Cocoa.h
    |   `-- Modules
    |       `-- module.modulemap
    `-- Current -> A

7 directories, 4 files

These are my environment variables:


$ env | grep -i osx
OSXCROSS_LIBLTO_PATH=
OSXCROSS_BUILD_DIR=/opt/osxcross/build
OSXCROSS_PATCH_DIR=/opt/osxcross/build/../patches
OSXCROSS_LINKER_VERSION=711
SDKROOT=/opt/osxcross/target/SDK/MacOSX15.1.sdk
OSXCROSS_OSX_VERSION_MIN=10.13
OSXCROSS_TARBALL_DIR=/opt/osxcross/build/../tarballs
OSXCROSS_DIR_SDK_TOOLS=/opt/osxcross/target/bin/../SDK/MacOSX15.1.sdk/../tools
OSXCROSS_BASE_DIR=/opt/osxcross/build/..
OSXCROSS_SDK_VERSION=15.1
OSXCROSS_VERSION=1.5
OSXCROSS_TARGET=darwin24.1
OSXCROSS_SDK_DIR=/opt/osxcross/target/bin/../SDK/MacOSX15.1.sdk/..
OSXCROSS_TARGET_DIR=/opt/osxcross/target/bin/..
IOS_TOOLCHAIN_ROOT=/opt/osxcross/build/cctools-port/usage_examples/ios_toolchain/target
OSXCROSS_SDK=/opt/osxcross/target/bin/../SDK/MacOSX15.1.sdk
MACOS_SDK=MacOSX15.1.sdk
OSXCROSS_ROOT=/opt/osxcross
OSXCROSS_CCTOOLS_PATH=/opt/osxcross/target/bin

Any suggestions?
Thanks

Steps to reproduce

Install Osxcross and try cross-compiling Godot-cpp from Ubuntu/Debian

Minimal reproduction project

N/A

Activity

  1. enetheru commented on Mar 22, 2025

    @enetheru
    Collaborator

    ooh nice, ok so I have no experience with OSXCROSS, there is no cmake code explicitly catering for it, but there shouldnt be a need for that.

    Why u no build a toolchain file to hand to cmake to reduce the amount of command line?

    I notice that you don't specify CMAKE_SYSROOT, or the CMAKE_FIND_ROOT_PATH

    This might be useful to read: https://stackoverflow.com/questions/63929668/cmake-cross-compilation-with-sysroot-returns-wrong-include-paths

    aswell as this: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#id8

    If I can setup a test environment I will do more, but I dont have a physical or virtual linux machine on hand to test with, so it might take me a bit of time to get to this.

    In the meantime if you figure anything out please let me know if there is anything I need to change. Cheers.

  2. kroketio commented on Mar 23, 2025

    @kroketio
    1. maybe try using -DCMAKE_TOOLCHAIN_FILE=/root/osxcross/target/toolchain.cmake
    2. set OSXCROSS_HOST env

    I also had to patch /root/osxcross/target/bin/x86_64-apple-darwin23.6-ld but thats a different story.

    /root/osxcross/target/toolchain.cmake

    # OSXCross toolchain
    
    macro(osxcross_getconf VAR)
      if(NOT ${VAR})
        set(${VAR} "$ENV{${VAR}}")
        if(${VAR})
          set(${VAR} "${${VAR}}" CACHE STRING "${VAR}")
          message(STATUS "Found ${VAR}: ${${VAR}}")
        else()
          message(FATAL_ERROR "Cannot determine \"${VAR}\"")
        endif()
      endif()
    endmacro()
    
    osxcross_getconf(OSXCROSS_HOST)
    osxcross_getconf(OSXCROSS_TARGET_DIR)
    osxcross_getconf(OSXCROSS_TARGET)
    osxcross_getconf(OSXCROSS_SDK)
    
    set(CMAKE_SYSTEM_NAME "Darwin")
    string(REGEX REPLACE "-.*" "" CMAKE_SYSTEM_PROCESSOR "${OSXCROSS_HOST}")
    
    # specify the cross compiler
    set(CMAKE_C_COMPILER "${OSXCROSS_TARGET_DIR}/bin/${OSXCROSS_HOST}-clang")
    set(CMAKE_CXX_COMPILER "${OSXCROSS_TARGET_DIR}/bin/${OSXCROSS_HOST}-clang++")
    
    # where is the target environment
    set(CMAKE_FIND_ROOT_PATH
      "${CMAKE_FIND_ROOT_PATH}"
      "${OSXCROSS_SDK}"
      "${OSXCROSS_TARGET_DIR}/macports/pkgs/opt/local")
    
    # search for programs in the build host directories
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    # for libraries and headers in the target directories
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
    
    set(CMAKE_AR "${OSXCROSS_TARGET_DIR}/bin/${OSXCROSS_HOST}-ar" CACHE FILEPATH "ar")
    set(CMAKE_RANLIB "${OSXCROSS_TARGET_DIR}/bin/${OSXCROSS_HOST}-ranlib" CACHE FILEPATH "ranlib")
    set(CMAKE_INSTALL_NAME_TOOL "${OSXCROSS_TARGET_DIR}/bin/${OSXCROSS_HOST}-install_name_tool" CACHE FILEPATH "install_name_tool")
    
    set(ENV{PKG_CONFIG_LIBDIR} "${OSXCROSS_TARGET_DIR}/macports/pkgs/opt/local/lib/pkgconfig")
    set(ENV{PKG_CONFIG_SYSROOT_DIR} "${OSXCROSS_TARGET_DIR}/macports/pkgs")
    
  3. fatduckling commented on Mar 23, 2025

    @fatduckling
    ContributorAuthor

    Thanks @kroketio I'll try this.
    But after further investigation, do we even need the Cocoa library?
    I realise it's not even used, and it's only failing because of the REQUIRED clause in the find_library.
    Removing all instances of the Cocoa dependencies in the cmake file (or even just the REQUIRED keyword) makes the godot-cpp library compile just fine and the game launches fine on macOS without it.
    Also, it's just a header-only library I think, so we don't need to use find_library here I believe.

  4. kroketio commented on Mar 23, 2025

    @kroketio
  5. fatduckling commented on Mar 30, 2025

    @fatduckling
    ContributorAuthor

    Thanks very much @dsnopek @bruvzg
    Can we merge this to 4.4.1?

  6. dsnopek commented on Mar 31, 2025

    @dsnopek
    Collaborator

    I've marked it for cherry-picking, so it should it in the next batch to merge into the 4.4 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions